TinyTemplate
TinyTemplate copied to clipboard
Can't use templating in files with curly braces {}
I'm not sure if this is specific to the file I was working with or if it applies to all file that use curly braces, but I wanted to bring it up anyway.
It seems TinyTemplate uses just opening and closing curly braces { } to denote places to insert values into the template file.
I'm working on a project that generates a JavaScript project workspace and needs to insert some values into a few default JS files. However, when I try to use a JS file as a template, the TinyTemplate errors out, telling me that a matching curly brace is missing.
I have some JS like this:
const myObj = {
projectName: "{project_name}"
};
TinyTemplate should insert the value of project_name into this JS object, but TinyTemplate sees the opening brace of myObj as as signaling the start of an injection point for the templating engine and then breaks when it sees the first opening brace of the actual injection point.
Personally, I'd love to use TinyTemplate for my project because I really only need minimal templating capabilities so other options would bloat out my app unnecessarily. Are there any plans in the future to make TinyTemplate compatible with JavaScript files and other formats that use curly braces extensively?
Similar issue, but with CSS. I've got a <style></style>
tag in my HTML, and CSS blocks use {}
so TinyTemplate is having some trouble parsing that. TinyTemplate is prefect since I'm not doing anything too complicated and I don't need a full-on rendering engine either :stuck_out_tongue:
@bnheise I'm literally having the exact same problem as you. Want to inject values into a JSON template, but it seems it's impossible. FWIW I started using handlebars-rust but I got into a state where rendering an array was not forming a correct JSON Object so just decided to move to this, which seems to not work at all 🤣
Gonna jump back to Handlebars, hope they fix this in a near future, I don't see this as an invalid use case tbh
Maybe leon will fix your problem? It supports escaping via "{" or "}".