In handlebars is it possible to render a partial and store the result in a handlebars variable?
I have a partial that I keep invoking and I want to expedite handlebars rendering so this result is only calculated once.
Is this possible to do in handlebars or do I need to add some tooling.
For context I am using java and https://github.com/jknack/handlebars.java
Some more robust solutions that come to mind are:
- create a cached helper function
- create a property that stores the result of this rendering in my java layer and make it cached and lazily evaluated
And number 2 seems the most robust.
How do people recommend solving this problem?
Here is an example of an outer template that calls input_type.hbs partial twice using the current context.
outer_template.hbs
interface SetterForBlah <T> {
Map<String, {{#with mapValueSchema}}{{> schema_input_type }}{{/with}}> getInstance();
T getBuilderAfterBlah(Map<String, {{#with mapValueSchema}}{{> schema_input_type }}{{/with}}> instance);
}
Note: even if I make the map value type a generic here, my implementing class would still have to render schema_input_type twice using mapValueSchema as the context.