HbsServer vs. HBS Templates in Vert.x (and registering helpers on HbsServer)

31 views
Skip to first unread message

Brian Sam-Bodden

unread,
May 26, 2017, 7:45:10 AM5/26/17
to handlebars.java
I have a Vert.x MVC app using HBS templates built with Gradle.

We have templates like `index.hbs` under the `/templates` directory that look like:

```
{{#partial "content"}}
<div class="jumbotron">
<h1>Welcome to the App</h1>
<p>Blah blah blah</p>
<p>
<a href="#" class="btn btn-primary btn-lg" role="button">Learn more</a>
</p>
</div>
{{/partial}}
{{> templates/layout}}
```

Then our layout `layout.hbs` looks like:

```
<html lang="en">
<head>...</head>
<body>
{{#block "content" }}
{{/block}}
</body>
</html>
```

That works great. On the same project I've added a Gradle task to run the hbsServer in order to preview templates (for designers) that looks like:

```
configurations {
hbsServer
}

dependencies {
hbsServer 'com.github.jknack:handlebars-proto:2.1.0'
}

task templateServer(type: JavaExec) {
main = 'com.github.jknack.handlebars.server.HbsServer'
classpath = configurations.hbsServer + sourceSets.main.runtimeClasspath
args '-dir', 'templates'
}
```

That also almost works, EXCEPT for 2 issues:

1) The HbsServer can't find the layout ({{> templates/layout}}). The error page reports that it is looking for `/app/templates/templates/layout.hbs` yet if I remove the `templates` it works in the HbsServer but breaks in Vert.x!

2) In our templates we have are using the `each` helper like:

```
{{#each navigation as |nav|}}
<li class="breadcrumb-item"><a href="{{nav.path}}">{{nav.display}}</a></li>
{{/each}}
```
On the HbsServer this breaks with the following error:

```
templates/layout.hbs:77:36: found: '|'
```

I assume that the issue here is that `each` helper can't be found (but I could be wrong).

Any hints would be appreciated.

Cheers,
Brian

Brian Sam-Bodden

unread,
May 26, 2017, 9:58:50 AM5/26/17
to handlebars.java
I got pass the helpers not being found just by upgrading to a higher version of the HbsServer, but the layout loading issue still remains :-( I'm using version 4.0.6 now of 'com.github.jknack:handlebars-proto'
Reply all
Reply to author
Forward
0 new messages