The use of PHP inside Smarty template files has been possible in previous versions of Smarty but is now deprecated.
You can however still do it by using a backwards compatibility wrapper.
This makes using PHP from inside a template file possible by doing:
{php}echo "Hello World";{/php}
Does anyone know of any problems or issues this might cause?
To expand the comments already given into a full answer, the problem with embedding arbitrary PHP code is that it breaks down the separation between PHP and Smarty.
Since Smarty compiles directly to PHP, everything you write in Smarty can be written in pure PHP, and may or may not end up just as readable, e.g.
<?= $foo ?> for {$foo} is fine<?php if ( $expr ): ?> Hello <?php endif; ?> for {if $expr} Hello {/if} is not too bad either<?= htmlspecialchars(strtoupper($foo ?: 'Hello')); ?> for {$foo|default:'Hello'|upper|escape:html} is a bit harder on the eyeThe main advantages I see of using Smarty (all of which are basically voided if you use {php}):
The only benefit you'd retain if you mixed Smarty and PHP would be those parts of Smarty syntax which are more readable than their PHP equivalent, like the modifier example I showed above.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With