Inheritance of templates and presenters

Notice: This thread is very old.
knyttl
Member | 196
+
0
-

Hey guys,

I have a hint concerning templates and presenters inheritance. For inst. let's consider some presenters, which inherit their properties as follows:

Base
+ Fruits
+-- Apples
+-- Pears
+ Vegetables
+-- Salades
+-- Onions

So for BasePresenter I define base template @layout.latte and for each inherited presenter I define its own template which sets some properties for the parent. For inst.

@layout.latte

<html><body>
{include #body}
</body></html>

Fruits/default.latte

{block body}
<h1>Fruits</h1>
{include #fruits_body}
...
{include #fruits_footer}
{/block}

Apples/default.latte

{block fruits_body}...{/block}
{block fruits_footer}...{/block}

The problem is, that even though ApplesPresenter extends FruitsPresenter, Nette tries to inherit the Apple template properties directly from @layout.latte. To achieve the correct behavior, one must add {extends ../Fruits/default.latte} to each Apples/default.latte, Pears/default.latte even though it should be inherited automatically by the presenter inheritance. Also, one must add {layout '../@layout.latte'} to Fruits/default.latte.

Last edited by knyttl (2011-08-13 11:40)

voda
Member | 561
+
0
-

Hello, I think there is no way you can avoid writing {layout ‘../@layout.latte’} to Fruits/default.latte, but maybe it is posibble to set the layout (../Fruits/default.latte) in Fruits::beforeRender with the Nette\Application\UI\Presenter::setLayout() method. It shoudn't be necessary to repeat it in each template of each descendant od FruitPresente.

voda
Member | 561
+
0
-

Another idea, for the second part you could try edit the Nette\Application\UI\Presenter::formatLayoutTemplateFiles() method.

duke
Member | 650
+
0
-

By edit, you probably mean override…

Last edited by duke (2011-08-14 04:39)

voda
Member | 561
+
0
-

Yes, of course. Editing methods directly in the framework isn't a good idea.