|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Tue Feb 16, 2016 12:38 am Post subject: Use PHP source file itself as a template. |
|
|
Code: | $smarty->registerFilter('pre',
function($tpl_source, Smarty_Internal_Template $template)
{
$stack = stristr($tpl_source, '__HALT_COMPILER');
return $stack ? substr($stack, strpos($stack, '?>') + 2) : $tpl_source;
}
); |
Your main code file should look similar to Code: | <?php
require_once 'smarty-config.php';
$smarty->assign(array('x' => 2, 'y' => 3));
$smarty->display(__FILE__);
__halt_compiler();
?>{$x*$y} |
Very useful for quick tests and demo pieces.
Last edited by AnrDaemon on Mon Dec 05, 2016 1:42 am; edited 2 times in total |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|