martenframework / marten

The pragmatic web framework.
https://martenframework.com
MIT License
407 stars 23 forks source link

Add the ability to configure how unknown template variables behave #109

Closed ellmetha closed 1 year ago

ellmetha commented 1 year ago

Description

Unknown template variables always result in Marten::Template::Errors::UnknownVariable exceptions being raised. This doesn't make it easy to deal with "shared" templates where variables may or may not be defined in the specified context. Instead, the default behavior should involve rendering unknown variables as empty strings while also making it possible to raise Marten::Template::Errors::UnknownVariable exceptions if the Marten template engine is configured accordingly.

Default behavior for unknown template variables

Let's ensure that unknown template variables are rendered as nil values by default.

Configuration

Let's introduce a new templates.strict_variables setting allowing to configure whether unknown variables will result in Marten::Template::Errors::UnknownVariable exceptions being raised. The default value should be false.