public function exec($_template,array $_data=array(),$_skin=null,$_type='php',&$_buffer=null) { }
public function exec($_template,array $_data=array(),$_skin=null,$_type='php',&$_buffer=null) { if (!isset($_skin)) $_skin = $this->api->cfg['default_skin']; if (!$_filename = $this->getFile($_template,$_skin,$_type)) return ''; $_parent = null; $_api = $this->api; // $R = function($name) use ($_template, $_skin) { echo "/res/t/{$_skin}/{$_template}/$name"; }; // $BEGIN = function($blockname) { ob_start(); }; // $END = function($blockname) use (&$_buffer,$_parent) { if (isset($_buffer[$blockname])) { ob_end_clean(); echo $_buffer[$blockname]; } else { $_buffer[$blockname] = isset($_parent)?ob_get_clean():ob_get_flush(); } }; // $EXTEND = function($template,$type=null) use (&$_parent) { if ($template) $_parent =array($template,$type); }; // $INCLUDE = function($template,$type=null) use ($_data,$_api,$_skin) { if ($template) echo $_api->templater->exec($template,$_data,$_skin,$type); }; // css- dom- $CLASS = function() use ($_template,$_skin) { echo "t-{$_template} s-{$_skin}"; }; if (!isset($this->instructions)) $this->instructions = $this->getInstructions(); // $V = function(&$var,$default='',$raw=false) use ($api) { if (isset($var)) { if (is_scalar($var)) echo $raw?$var:htmlspecialchars($var); else $api->templater->dump($var); } else { echo $raw?$default:htmlspecialchars($default); } }; // $GV = function(&$var,$default='') { if (isset($var)) return $var; else return $default; }, extract($_data); // - - ( , ) if (!isset($_language)) $_language = $this->api->cfg['default_language']; $L = function(&$stringhash,$default=array('?')) use ($_language,$_api) { if (!isset($stringhash)) $stringhash = $default; if (is_string($stringhash)) { echo htmlspecialchars($stringhash); return; } if (isset($stringhash[$_language[0]])) echo htmlspecialchars($stringhash[$_language[0]]); elseif (isset($stringhash[$_api->cfg['default_language'][0]])) echo htmlspecialchars($stringhash[$_api->cfg['default_language'][0]]); else echo htmlspecialchars(reset($stringhash)); }; extract($this->instructions); ob_start(); include $_filename; $content = ob_get_clean(); if ($_parent) $content = $this->exec($_parent[0],$_data,$_skin,$_parent[1],$_buffer); return $content; }
<?foreach($GV($pictures,array()) as $picture):?> <img src="<?$R($picture)?>"/> <?endforeach;?>
<!DOCTYPE html> <html class="<?$CLASS()?>" id="<?$V($_id)?>"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> <title><?$L($title,array('en'=>'No title','ru'=>' '))?></title> <link rel="stylesheet" href="/res/var/t.css?<?=$_api->build?>" type="text/css" media="all" /> <script type="text/javascript" src="/res/jquery.js?<?=$_api->build?>"></script> <script type="text/javascript" src="/res/var/t.js?<?=$_api->build?>"></script> <script type="text/javascript" src="/res/var/frontend.js?<?=$_api->build?>"></script> </head> <body> <header> <?$BEGIN('header')?> <h1><?$L($title,array('en'=>'No title','ru'=>' '))?></h1> <?$SLOT($langswitch)?> <?$END('header')?> </header> <section> <?$BEGIN('content')?> <?$L($content,array('en'=>'No content','ru'=>' '))?> <?$END('content')?> </section> <footer> <?$BEGIN('footer')?> <?$SLOT($menu_footer)?> <p class="copy"> <?=date('Y')?> MyProject </p> <p class="info"> <?$s=array('en'=>'Generated','ru'=>'');$L($s)?>: <?=date('r')?> </p> <?$END('footer')?> </footer> </body> </html>
. {background: url("<?$R('bg.png')?>")} . > .left {width: <?$C('left-margin')?>; border: 1px <?$C('border-color')?> solid;}
Source: https://habr.com/ru/post/136516/