smarty-php / smarty

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

Suggestion: {namspace} compile tag #1008

Open SlowFox71 opened 5 months ago

SlowFox71 commented 5 months ago

I experience quite frequently that class constants or enums have to be used in templates, e.g. in but not limited to if-conditions. These constants are typically located in namespaces.

Smarty templates for now reside in the root namespace, requiring to use absolute paths. Quite often all constants are from the same namespace, so that a {namespace} tag could make the template easier to handle, kind of this:

{namespace Foo\Bar\Baz}

{if $item->getSomeProperty() === ItemProperty::SomeValue}
   <p>this</p>
{elseif $item->getSomeProperty() === ItemProperty::SomeOtherValue}
   <p>that</p>
{elseif ...}
{else}
  <p class="warning">some property is not valid</p>
{/if}

{/namespace}