Named conditions in Smarty templates
Problem Statement
Currently, Smarty templates rely on traditional comparison operators such as >
, <
, <=
, >=
, ==
, and !=
within {if}
statements. However, there are cases where these operators may not always be appropriate or desirable within templates, either due to readability concerns or syntax restrictions. Smarty provides a way to use named conditions (e.g., gt
, lt
, eq
, neq
), but this is not currently implemented in the Hazaar Smarty integration.
Who will benefit?
- Developers working with Smarty templates who require clearer and more readable conditionals.
- Users dealing with scenarios where traditional operators may be problematic in certain contexts.
Benefits and risks
Benefits
- Improves template readability and maintainability.
- Aligns Hazaar's Smarty implementation with the broader Smarty feature set.
- Provides an alternative syntax that may be necessary in certain environments.
Risks
- Potential for minor backwards compatibility concerns if existing templates assume only standard operators.
- May introduce additional parsing complexity within the template engine.
Proposed solution
Implement support for named conditions in Smarty templates, allowing conditionals such as:
{if $something gt $somethingelse}
instead of
{if $something > $somethingelse}
This should support all standard named conditions provided by Smarty, including gt
, lt
, eq
, neq
, gte
, lte
, and
and or
.
Priority/Severity
-
High (This will bring a huge increase in performance/productivity/usability/legislative cover) -
Medium (This will bring a good increase in performance/productivity/usability) -
Low (anything else e.g., trivial, minor improvements)
Edited by Jamie Carl