Template inheritance in components

Upozornění: Tohle vlákno je hodně staré a informace nemusí být platné pro současné Nette.
LRJ
Člen | 6
+
+3
-

Is there any possibility to implement template inheritance in components (like it is in presenters) without using macros in latte files?
E.g. in render method set parent template (layout) and child template.

David Kudera
Člen | 455
+
-1
-

We used that for some forms. All our forms were wrapped in control (like here) and had base template (eg. app/components/forms/template.latte)

Than each form had it's own template (eg. app/components/signUp/template.latte).

In createTemplate method (we wanted to keep render method clean) in base control we set base file template and also look for form specific template:

$template->setFile(__DIR__. '/template'); 	// which is app/components/forms/template.latte
$template->formTemplate = dirname($this->getReflection()->getFileName()). '/template.latte';

this second line will use template.latte file in same directory where your form class is.

and base template:

<div class="some-form-wrapper">
	{include $formTemplate}
</div>

But I think that because of this reflection „thing“ it is not the cleanest solution.

LRJ
Člen | 6
+
0
-

Thanx for answer but this but that's exactly what I don't want. I mean I would like to be able do it without any macro in latte file :)
Sorry for posting en thread into cz forum

David Kudera
Člen | 455
+
0
-

Ou, I see. Than I think that it will not be possible. And why can't you use any macros?

arron
Člen | 464
+
0
-

I was trying to hack it somehow, but with no success :-/ Now I do in in a way, that in ControlBase (or similar class) I set the template variable $layoutToExtend and in the child control I have {layout $layoutToExtend}.

It is not as elegant I'd like to be, but it is good enaugh.

David Matějka
Moderator | 6445
+
0
-

This PR would make it easy.

But I think, custom MacroSet with „finalize“ method and with code similar to this could work as well.

Editoval matej21 (19. 6. 2014 23:04)

LRJ
Člen | 6
+
0
-

Yes, eventually we had to do that in similar way too :/ I really don't understand why it can't be simply done in code.

arron
Člen | 464
+
0
-

Still to complicated. The most convenient way would be some $template->extendFrom() method.