I have been testing Smarty3, and it appears that runtime template
inheritance doesn't work.
For instance if I try:
{extend file=$layout}
Where $layout is one of 'master.tpl', 'master_no_ads.tpl'.
It doesn't really work currently because the compiled template assumes
that the extended file isn't dynamic, so whatever was loaded first is
what is displayed.
I looked at the code, and it looks like runtime inheritance isn't
something that was considered with the current design of block/extend.
There are many nice use cases for runtime inheritance. For instance,
if you two site layouts (e.g. one with ads, and one without ads), then
you could use runtime inheritance to make each page template work. It
also allows the fetching of individual blocks, which is really handy
when using templates for email.
Regards,
John Campbell
Unfortunately that really wont work, as it makes things too slow to
run on a production system.
I may invest the effort to implement this. I have longed for a php
templating system that is feature competitive with Django or Rails
Views.
It seems to me that a compiled block should just store it's content on
a named stack, and, if the template isn't extending another template,
then you should go through the stack and send the output. The extend
command should just add an 'include' at the end of the template.
Does that make sense? The good news is that implemented this way,
there would be no need to do dependency checking at runtime.
Regards,
John Campbell
I spent some time working on it. I got pretty close by using the
extend resource type with:
$tpl->display("extend:$layout|page.tpl");
The only thing I had to change was how the resource name was
generated. It was still a little half baked with regards to
invalidating the compiled template.
Is the extend resource type something that is going to be maintained?
I didn't see any unit tests, and I thought it may be something that is
going to go away.
- - -
Another question, is there a way to access the contents of the parent
block, from the child block. It would be nice to be able to do:
{block name="navigation"} Add something at the top
{$smarty.block.parent} Add something at the bottom{/block}
Thanks for the help.
John Campbell