-
Notifications
You must be signed in to change notification settings - Fork 290
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
[Feature Request] Ability to change start and stop delimiters #343
Comments
If you want to interpolate variables from Tera yes :/ |
I see, I may need to look around at alternatives for now, then. Thanks for the quick response and for your work on Tera and Gutenberg! |
Re-opening it, it's worth having open to think about it |
Fair enough. The ability to switch delimiters would really open up some applications. In the rust ecosystem, there are many HTML templating crates, but I've been having a hard time trying to find one that can generalize to something like LaTeX like Jinja2 does. |
I've grown to really like Tera over the years, and still would love to template some LaTeX files. Is there any guidance you could give me if I wanted to do this, even if it involves a local fork with hard-coded changes to the delimiters? E.g., how would I hardcode an alternative parser with different delimiters in a duplicate grammar? |
You can fork the repo and replace https://github.com/Keats/tera/blob/master/src/parser/tera.pest#L148-L155 to use your delimiters of choice |
I think many people see value here. The catch seems to be an implementation detail. As I understand it, the Tera parser is generated at compile time with hardcoded template delimiters. This leaves the question: what are good ways to create a parser with user-definable template delimiters. Here are two options I see:
Of course, some choices of custom template delimiters might clash with other syntax. The library could check for clashes perhaps. Of course, the above options have complexity and tradeoffs. I'm not very familiar with the idea of user customizations of parsers. Perhaps others see other ways? |
It's not really doable for v1 but it should be pretty easy for v2 to implement that. |
With the template delimiters as
{{
}}
{%
, etc., is there a way to use Tera in content that heavily uses these curly braces and%
? For example, if I wanted to use tera to template a LaTeX section like this:Trying to template
name.last
Tera fails to parse with the error:
presumably due to the conflicting use of
{}
and%
.Using jinja options, I am able to switch delimiters:
which allows me to make a template that looks like the following and parses correctly:
But, without being able to change delimiters in Tera, am I stuck? Is it impossible to use tera in templates that already use curly braces and percentage signs?
The text was updated successfully, but these errors were encountered: