@@ -36,6 +36,24 @@ 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 ' ]);
41+ }
42+
43+
44+ /**
45+ * Initializes before template parsing.
46+ * @return void
47+ */
48+ public function initialize ()
49+ {
50+ $ this ->getCompiler ()->addMethod ('getExtends ' , '
51+ if (empty($this->params["_g"]->extended)) {
52+ $this->params["_g"]->extended = __CLASS__;
53+ }
54+ return $this->params["_g"]->extended === __CLASS__ && isset($this->params["_control"]) && $this->params["_control"] instanceof Nette\Application\UI\Presenter
55+ ? $this->params["_control"]->findLayoutTemplateFile() : NULL;
56+ ' );
3957 }
4058
4159
@@ -103,6 +121,18 @@ public function macroIfCurrent(MacroNode $node, PhpWriter $writer)
103121 }
104122
105123
124+ /**
125+ * {extends auto}
126+ */
127+ public function macroExtends (MacroNode $ node , PhpWriter $ writer )
128+ {
129+ if ($ node ->modifiers || $ node ->parentNode || $ node ->args !== 'auto ' ) {
130+ return FALSE ;
131+ }
132+ $ this ->getCompiler ()->addMethod ('getExtends ' , 'return $this->params["_presenter"]->findLayoutTemplateFile(); ' );
133+ }
134+
135+
106136 /** @deprecated */
107137 public static function renderSnippets (Nette \Application \UI \Control $ control , \stdClass $ local , array $ params )
108138 {
0 commit comments