4 * Smarty Internal Plugin Compile extend
5 * Compiles the {extends} tag
13 * Smarty Internal Plugin Compile extend Class
16 * @subpackage Compiler
18 class Smarty_Internal_Compile_Extends extends Smarty_Internal_CompileBase
21 * Attribute definition: Overwrites base class.
24 * @see Smarty_Internal_CompileBase
26 public $required_attributes = array('file');
28 * Attribute definition: Overwrites base class.
31 * @see Smarty_Internal_CompileBase
33 public $shorttag_order = array('file');
36 * Compiles code for the {extends} tag
38 * @param array $args array with attributes from parser
39 * @param object $compiler compiler object
41 * @return string compiled code
43 public function compile($args, $compiler)
45 // check and get attributes
46 $_attr = $this->getAttributes($compiler, $args);
47 if ($_attr['nocache'] === true) {
48 $compiler->trigger_template_error('nocache option not allowed', $compiler->lex->taglineno);
50 if (strpos($_attr['file'], '$_tmp') !== false) {
51 $compiler->trigger_template_error('illegal value for file attribute', $compiler->lex->taglineno);
54 $name = $_attr['file'];
55 /** @var Smarty_Internal_Template $_smarty_tpl
56 * used in evaluated code
58 $_smarty_tpl = $compiler->template;
59 eval("\$tpl_name = $name;");
60 // create template object
61 $_template = new $compiler->smarty->template_class($tpl_name, $compiler->smarty, $compiler->template);
62 // check for recursion
63 $uid = $_template->source->uid;
64 if (isset($compiler->extends_uid[$uid])) {
65 $compiler->trigger_template_error("illegal recursive call of \"$include_file\"", $compiler->lex->line - 1);
67 $compiler->extends_uid[$uid] = true;
68 if (empty($_template->source->components)) {
69 array_unshift($compiler->sources, $_template->source);
71 foreach ($_template->source->components as $source) {
72 array_unshift($compiler->sources, $source);
74 if (isset($compiler->extends_uid[$uid])) {
75 $compiler->trigger_template_error("illegal recursive call of \"{$source->filepath}\"", $compiler->lex->line - 1);
77 $compiler->extends_uid[$uid] = true;
81 $compiler->inheritance_child = true;
82 $compiler->lex->yypushstate(Smarty_Internal_Templatelexer::CHILDBODY);