@@ -36,10 +36,28 @@ public static function install(Latte\Compiler $compiler)
3636 $ me ->addMacro ('plink ' , [$ me , 'macroLink ' ]);
3737 $ me ->addMacro ('link ' , [$ me , 'macroLink ' ]);
3838 $ me ->addMacro ('ifCurrent ' , [$ me , 'macroIfCurrent ' ], '} ' ); // deprecated; use n:class="$presenter->linkCurrent ? ..."
39+ $ me ->addMacro ('extends ' , [$ me , 'macroExtends ' ]);
40+ $ me ->addMacro ('layout ' , [$ me , 'macroExtends ' ]);
3941 $ me ->addMacro ('includeblock ' , [$ me , 'macroIncludeBlock ' ]);
4042 }
4143
4244
45+ /**
46+ * Initializes before template parsing.
47+ * @return void
48+ */
49+ public function initialize ()
50+ {
51+ $ this ->getCompiler ()->addMethod ('getExtends ' , '
52+ if (empty($this->params["_g"]->extended)) {
53+ $this->params["_g"]->extended = __CLASS__;
54+ }
55+ return $this->params["_g"]->extended === __CLASS__ && isset($this->params["_control"]) && $this->params["_control"] instanceof Nette\Application\UI\Presenter
56+ ? $this->params["_control"]->findLayoutTemplateFile() : NULL;
57+ ' );
58+ }
59+
60+
4361 /**
4462 * Finishes template parsing.
4563 * @return array(prolog, epilog)
@@ -104,6 +122,18 @@ public function macroIfCurrent(MacroNode $node, PhpWriter $writer)
104122 }
105123
106124
125+ /**
126+ * {extends auto}
127+ */
128+ public function macroExtends (MacroNode $ node , PhpWriter $ writer )
129+ {
130+ if ($ node ->modifiers || $ node ->parentNode || $ node ->args !== 'auto ' ) {
131+ return FALSE ;
132+ }
133+ $ this ->getCompiler ()->addMethod ('getExtends ' , 'return $this->params["_presenter"]->findLayoutTemplateFile(); ' );
134+ }
135+
136+
107137 /**
108138 * {includeblock "file"}
109139 */
0 commit comments