templatel icon indicating copy to clipboard operation
templatel copied to clipboard

unrecognized variable name

Open markokocic opened this issue 4 years ago • 2 comments

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

markokocic avatar Mar 11 '21 15:03 markokocic

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! 🙇🏾

clarete avatar Mar 14 '21 15:03 clarete

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.

markokocic avatar Mar 15 '21 10:03 markokocic