emacs-love / templatel

Jinja inspired template language for Emacs Lisp
https://emacs.love/templatel
GNU General Public License v3.0
54 stars 5 forks source link

unrecognized variable name #10

Open markokocic opened 3 years ago

markokocic commented 3 years ago

Not sure if this is templatel or weblorg issue, filling it here.

I have defined a template variable named date-format inside a weblorg-site definition.

When I try to generate the website, I get the following error message:

Template Error: home.html: Variable `date' not declared
clarete commented 3 years ago

hi @markokocic! thank you for opening the issue. I think this is indeed on templatel's side, and it might unfortunately be by design. The reason this happens is that the dash between the two words is seen as the infix operator for subtraction within templatel.

That's indeed a long way to say that templatel's variables must match the expression [a-zA-Z_][a-zA-Z0-9_]*. In other words, the first character must be either a letter between a and z or underscore, and the rest of the name can also contain numbers.

Emacs Lisp uses prefix notation since everything is implemented as functions, but there is no great translation between that and Jinja2's syntax which is built after Python's infix. I decided to follow Jinja's style as the overall direction of templatel, so I think we should at the very least get this exact example and add it to the documentation, because I believe this might be confusing other people as well.

Once again, thanks for raising the issue! 🙇🏾

markokocic commented 3 years ago

Thanks, @clarete, looks like it was just wrong expectations from my side that variable names will follow lisp rules instead of python rules. You are right, having one example might mitigate the confusion.