Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TemplateHandler does not work for single route #366

Closed
nikku opened this issue May 4, 2016 · 3 comments
Closed

TemplateHandler does not work for single route #366

nikku opened this issue May 4, 2016 · 3 comments
Assignees
Labels

Comments

@nikku
Copy link

nikku commented May 4, 2016

Version

  • vert.x core: 3.3.0-SNAPSHOT
  • vert.x web: 3.3.0-SNAPSHOT

Context

I'd like to use the TemplateHandler for selected, single routes like that:

TemplateHandler templateHandler = TemplateHandler.create(engine);

router.get("/foo").handler(ctx -> {
  ctx.put("foo", "bar");
}).handler(templateHandler);

This, however does not work due to the fact that Utils#pathOffset assumes templates to reside in a nested route (and produces a wrong template location because of that).

Steps to reproduce

Reproduce with the following test case:

  @Test
  public void testTemplateHandlerSingleRoute() throws Exception {
    TemplateEngine engine = new TestEngine(false);
    router.route("/test-template")
             .handler(context -> {
               context.put("foo", "badger");
               context.put("bar", "fox");
               context.next();
             })
            .handler(TemplateHandler.create(engine, "somedir", "text/html"));

    // we assume test-template is going to be
    // mapped to {somedir}/test-template.html and
    // rendered correctly with pre-setup context variables
    String expected =
      "<html>\n" +
        "<body>\n" +
        "<h1>Test template</h1>\n" +
        "foo is badger bar is fox<br>\n" +
        "</body>\n" +
        "</html>";

    testRequest(HttpMethod.GET, "/test-template", 200, "OK", expected);
  }
@nikku
Copy link
Author

nikku commented May 4, 2016

Pull request #367 adds failing test case.

@pmlopes
Copy link
Member

pmlopes commented May 11, 2016

We need a review on #371 since it fixes this particular issue but I'm not sure if this is the desired behavior.

@pmlopes
Copy link
Member

pmlopes commented Jan 27, 2017

As it was discussed on #371 for a single path use the engine directly.

@pmlopes pmlopes closed this as completed Jan 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging a pull request may close this issue.

2 participants