Open dvtate opened 1 week ago
user
in your case) and values that can be specified or unspecified depending on a data
instance? Mustache cannot enforce non-emptiness of values. If you really need to make the prefilling work (see the next point) then you can derive from kainjow::mustache::context
and replace certain {{...}}
sections with themselves - or, if there are just few of such sections, just do global_data.set("{{user}}", "{{user}}");
and so on for each.For now I'm using std::regex_replace on the templates before passing them into mustache... Maybe later I'll come up with something better.
This is a C++ framework so performance is usually pretty important for C++ devs, even if it's only a few percentage points improvement.
If you have control of this template, you could maybe try the set delimiter tags and use different characters for the fields you want to pre-populate, then render that template with pre-populated fields, which would produce the final template for dynamic data.
For example, render this with a "server" value:
{{=[[ ]]=}}
Hello {{user}}, welcome to [[server]].
which would then produce:
Hello {{user}}, welcome to localhost.
I'd like to pre-populate some fields in a template that will always be the same in order to improve performance. For example:
I'd like to prepopulate
{{server}}
since it will not change and this template will be generated potentially millions of times.My first naive attempt to do this looked like this:
However this deletes the
{{user}}
field so the coderesults in
So, two questions:
"{{variable}}"
?Thanks!