|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
TimBroddin Smarty n00b
Joined: 29 Nov 2010 Posts: 1
|
Posted: Mon Nov 29, 2010 2:21 pm Post subject: dynamic extends |
|
|
Hi there,
Thanks for the great work on Smarty. I love the new functionality in Smarty 3.
I'm working on a project where we have a number of parent templates and a number of child templates which we mix and match. I'm trying this:
{extends file=$extend_template}
But it does not seem to work because Smarty compiles the file dependencies and caches them in templates_c.
Does anyone know a workaround for this? At this moment I have turned force compile on but that's not the ideal solution. |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Mon Nov 29, 2010 2:28 pm Post subject: |
|
|
As block replacement in template inheritance is a compile time porcess you can't make dynamic extends by using assigned variables and the {extedns } tag.
Use the "extends" resource instead to define the parent/child template relation ships. |
|
Back to top |
|
starkj Smarty n00b
Joined: 23 Nov 2015 Posts: 1
|
Posted: Mon Nov 23, 2015 9:17 am Post subject: |
|
|
hi,
just run into the same problem.
I want to set the template which is extended dynamically. Yes, this does not work in the first place since a template is complied once with the parent set at the first time. And disabling the cache is definitely a thing you don't want to do.
My template looks something like this:
Code: |
{extends $parentTemplate}
{block name='content'}
foo
{/block
|
To make this work anyway, you can set a custom compileId for which I use the parent templates name:
Code: |
$smarty->assign($parameters);
$smarty->setCompileId($parameters['parentTemplate']);
$xmarty->fetch('template.html.tpl');
|
or
Code: |
$smarty->assign($parameters);
$smarty->fetch('template.html.tpl', null, $parameters['parentTemplate']);
|
This is meant to be a workaround and not best practice. The proper way to go is like already mentioned: Use the extends resource just to define parent/child relationship and then structure your templates in a way that you can do the rest by using blocks.
Regards |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|