Template inheritance in components
- David Kudera
- Člen | 455
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.
- David Kudera
- Člen | 455
Ou, I see. Than I think that it will not be possible. And why can't you use any macros?
- arron
- Člen | 464
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.