Passing things to partials and functions

174 views
Skip to first unread message

Andy M

unread,
Jul 28, 2017, 7:08:52 AM7/28/17
to mustache.java
I'm having a problem passing things around in mustache java. Historically what we've had is things like:

{{</partials/form/_form}}
{{$formContents}}

{{</partials/form/_text}}
{{$field}}hours{{/field}}
{{$label}}Number of hours{{/label}}
{{$inputAttributes}}size="2"{{/inputAttributes}}
{{$inputClasses}}inline {{/inputClasses}}
{{//partials/form/_text}}

{{</partials/form/_submit}}
{{$field}}next{{/field}}
{{//partials/form/_submit}}

{{/formContents}}
{{//partials/form/_form}}

Which works fine - however, I now need to be able to track what labels were assigned against a field. I was hoping that $formContents would be evaluated at the 
point the partial is called - but it seems it's evaluated at the point it's referenced in the partial.

I've also tried creating a function something along the lines of:
{{#formContents}}
{{</partials/form/_text}}
{{$field}}hours{{/field}}
{{$label}}Number of hours{{/label}}
{{$inputAttributes}}size="2"{{/inputAttributes}}
{{$inputClasses}}inline {{/inputClasses}}
{{//partials/form/_text}}

{{</partials/form/_submit}}
{{$field}}next{{/field}}
{{//partials/form/_submit}}
{{/formContents}}

{{>/partials/form/_form}}

which was a last ditch attempt to get this working but it seems that mustache will fail compilation whenever a partial is used inside a function?

Any help greatly appreciated!

Andy M

unread,
Jul 28, 2017, 7:14:20 AM7/28/17
to mustache.java
Possibly worth mentioning the error in the second case is:

com.github.mustachejava.MustacheException: Failed to close '/partials/form/_submit' tag at line 1

at com.github.mustachejava.MustacheParser.compile(MustacheParser.java:242)
at com.github.mustachejava.MustacheParser.compile(MustacheParser.java:124)
at com.github.mustachejava.MustacheParser.compile(MustacheParser.java:42)
at com.github.mustachejava.DefaultMustacheFactory.lambda$getFragmentCacheFunction$0(DefaultMustacheFactory.java:170)
at com.github.mustachejava.DefaultMustacheFactory$$Lambda$11/1817154869.apply(Unknown Source)
Reply all
Reply to author
Forward
0 new messages