|
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 |
cardmeister Smarty n00b
Joined: 29 Mar 2012 Posts: 2
|
Posted: Wed Dec 04, 2013 2:07 pm Post subject: Smarty 3.1.15 - {include} in {block} ignores tpl dirs |
|
|
Versions:
3.1.15
SVN Trunk (12/4/2013)
Problem:
When placing an {include} inside a {block} tag, the template directory list is not considered past the first render.
templates/default/content.tpl
Code: |
I have a block with a sub-template.
{block name='sub'}
{include 'sub.tpl'}
{/block}
|
templates/default/sub.tpl
Code: |
I am the default sub-template
|
templates/site1/sub.tpl
Code: |
I am site1's sub-template
|
test.php
Code: |
$smarty = new Smarty()
$tpl_dirs = array("/templates/$current_site/", "/templates/default");
$smarty->setTemplateDir($tpl_dirs);
$smarty->display('content.tpl');
|
Expected Result:
When page is executed for site1, content from site1/sub.tpl is displayed.
When page is executed for site2, content from default/sub.tpl is displayed.
This is consistent with the behavior when {include} is not enclosed in a {block} tag.
Actual Result:
If page is executed for site1 first, then content from site1/sub.tpl is always displayed.
Similarly, if page is executed for site2 first, then content from default/sub.tpl is always displayed.[/b] |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Wed Dec 04, 2013 11:32 pm Post subject: |
|
|
Currently template inheritance and the processing of {block} tags is a compile time process. As included subtemplate could also contain {block} tags its code is merged at compile time into the compiled template of content.tpl. If you change your template dirs later this change is not seen.
The solution is to use a compile_id
Code: | $smarty = new Smarty()
$tpl_dirs = array("/templates/$current_site/", "/templates/default");
$smarty->compile__id = $current_site;
$smarty->setTemplateDir($tpl_dirs);
$smarty->display('content.tpl'); |
This restriction will be removed in the future when smarty 3.2 will be released. |
|
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
|