ventojs / vento

🌬 A template engine for Deno & Node
https://vento.js.org/
MIT License
212 stars 12 forks source link

Exception thrown on undefined data values #26

Closed UppaJung closed 8 months ago

UppaJung commented 10 months ago

Vento (via the JS enginge?) throws an exception if a value isn't defined.

Hence, if a is undefined and b is set to "foo", one would expect a ?? b or a || b to result in foo, but instead it results in an exception.

UppaJung commented 10 months ago

My workaround for problems like title being undefined has been to make sure everything that uses the template has an empty string assigned to title

title:
oscarotero commented 10 months ago

Yes, this is how JavaScript works and I think there's no way to call an undefined variable without throwing an error.

If you don't care if a variable is defined or not, use {{ it.varname }} instead of {{ varname }}. The it global variable contains all defined variables.

wrapperup commented 8 months ago

As of #43, this issue is fixed. @UppaJung give it a try once the new version is published.