Play framework 'set' template tag not working between files

242 views Asked by At

I'm working on a project using play framework 1.2.5

I have two custom tags files, one that does 'set' a value

#{set foo:'bar' /}

and another file that 'get' this value to make a decision to show some markup or not.

%{  if(foo) { %}
    #{doBody /}
%{ } }%

This used to work in a previous play version (don't recall which) and now is not working, I'm not sure if it was the upgrade itself or something else got broken.

As per play documentations for template engine tags, set should work between different files:

Define a value which can be retrieved in the same template or any layout with the get tag. http://www.playframework.com/documentation/1.2.3/tags#set

Any clue on what might be wrong?

thanks in advance

1

There are 1 answers

0
Gelin Luo On

set only works with child template passing data to extended template, e.g

parent template:

<html>
<title>${get 'title'}</titl>
...
</html>

child template:

$extends('parent.html')
${set title: 'My Title'/}

To pass data from one template to another template, you have to define the callee template as a tag. See play's document on more detail. Note I am not sure if tag could extend another tag, most probably it is not possible

If you are using PlayRythm plugin, then it is much easier. E.g. calling from template foo to bar could be as easy as

bar template:

Hello @who

foo template:

@bar("World")
@// or
@bar(who: "world")
@// or
@bar({who: "world"})

Note Rythm doesnot have a separate tag concept, literally every template is tag and you can call any template from another one or even do recursive call. You can try rythm's live interactive demo on http://fiddle.rythmengine.org/.

Disclaim: I am the creator and maintainer of Rythm template engine and Play-Rythm module