smarty-php / smarty

Smarty is a template engine for PHP, facilitating the separation of presentation (HTML/CSS) from application logic.
Other
2.24k stars 705 forks source link

Support the null coalescing operator #882

Closed wisskid closed 1 year ago

wisskid commented 1 year ago

Smarty has no support for the null coalescing operator. One might argue that it is not required, since the default modifier largely serves the same purpose. However, the default modifier is also triggered by an empty string: '', whereas the null coalescing operator would only replace a null value and leave everything else untouched.

Example:

{$myvar ?? 'undefined'}

This would render as 'undefined' if and only if:

Otherwise, it should return the value set for myvar.