Closed antoniogamiz closed 4 years ago
I thought lambdas could work but they cannot...
use Template::Mustache;
say Template::Mustache.render(
'{{#wrapped}} {{name}} is awesome. {{/wrapped}}'
, {wrapped => -> $text { $text }});
It sounds like you would want to use Inheritance, with several levels. For example, this spec test.
It would be possible to make a pragma to leave variables in place if they are not defined in the context. That's definitely not how mustache is designed, but it's a sensible and easy feature to add.
I'd rather use the Inheritance feature though, if I'm right that it would be a better fit for what you're ultimately trying to do.
I do not see how Inheritance with several levels can solve this. What I want is to generate the menu only once, to avoid replacing it with each HTML file generated. At this moment, I have implemented this behavior with two renders:
The problem is that the first render replaces all unused variables by an empty string, so the second render does nothing. I think if I use partials or inheritance, all menu data will have to be replaced with each HTML file, so it will take the same time. With these two renders, I reduce the generation time around 400 seconds.
You can see the changes in this commit: https://github.com/Raku/Documentable/commit/b683b7a9cf21c060988c67a50e8bc52179374118.
Now my question is, can I get that behavior with Inheritance?
I didn't get to trying your scenario with inheritance, but I did implement the pragma. It's not merged to master yet, but you can try it out in the keep-undef-pragma
branch.
Oh, that was fast. Thanks a lot, @softmoth, it's a great help to have this feature :).
I've committed this to master and released it to CPAN as version 1.2.2.
Hi, right now unused variables are replaced by an empty string:
Is there a way to disable this? Or is not possible? It would be extremely helpful to concatenate renders without replacing all variables at the same time.