Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't use templating in files with curly braces {} #34

Open
bnheise opened this issue Jan 30, 2023 · 4 comments
Open

Can't use templating in files with curly braces {} #34

bnheise opened this issue Jan 30, 2023 · 4 comments

Comments

@bnheise
Copy link

bnheise commented Jan 30, 2023

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?

@Robin5605
Copy link

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 😛

@aromeronavia
Copy link

@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

@NobodyXu
Copy link

Maybe leon will fix your problem?
It supports escaping via "{" or "}".

@prenone
Copy link

prenone commented Jun 22, 2023

Escaping curly braces is supported, as documented here, like this

.class-example \{
    color: blue
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants