I'm starting to work with Mustache on PHP and I don't manage to make wrapper functions to work as debt.
I have this template
{{#skill_level}}
<span class="stars">
{{#stars}}
{{skill_level}}
{{/stars}}
</span>
{{/skill_level}}
And I have this data
$data = new StdClass;
$data->skill_level = 3;
$data->stars = function($level) {
$aux = "";
$l = intVal($level);
for ($i = 0; $i < $l; $i++) {
$aux .= "+";
}
for ($i = $l; $i < 5; $i++) {
$aux .= ".";
}
return $aux;
};
I render m.render($tenplate, $data);
and I would like to obtain something like:
<span class="stars">
+++..
</span>
But it doesn't work.
I get
<span class="stars">
.....
</span>
Because Mustache
is passing "{{skill_level}}"
to my function instead of value 3
.
Furthermore if I change the template a put backspaces in the mustache labels:
{{ #skill_level }}
<span class="stars">
{{ #stars }}
{{ skill_level }}
{{ /stars }}
</span>
{{ /skill_level }}
Then {{ skill_level }}
is processed but it isn't sent to {{ #starts }}
, the render obtained is
<span class="stars">
3
</span>
So, does anybody know what I'm doing wrong? How should I wrote the template to make it works? Any advice or experience are welcome. Thanks.