简体   繁体   中英

Use PHP code in .TPL files in Kohana/Smarty Framework

I am unable to write PHP code in .tpl file in either ways

I tried <?php echo 'test'; ?> <?php echo 'test'; ?>

I also tried {PHP} echo 'test'; {/PHP} {PHP} echo 'test'; {/PHP}

But both returned error

on line 14 "{php}echo &quot;hello!&quot;{/php}" unknown tag "php"

I've not worked with Kohana, but with Smarty 3, use of the php tag is deprecated . You'll need to use the backwards compatibility mode with 3.0. It is highly recommended that all code logic be placed in your controller or php script files, and not your Smarty templates.

If you want to use PHP code in templates, it is suggested you create custom functions or modifiers .

So, basically, the short answer is find where your code (or the Kohana plugin) is instantiating Smarty and change it to use SmartyBC, but be aware that this is highly discouraged.

If you are using Kohana Smarty3 module for Kohana, these code lines should help set you in the right direction.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM