View previous topic :: View next topic |
Author |
Message |
UnstoppableCarl Smarty n00b
Joined: 10 Oct 2013 Posts: 3
|
Posted: Thu Oct 10, 2013 3:11 pm Post subject: variable template file names not allow within {block} tags |
|
|
I upgraded to smarty 3.1.15 and have found that many of my templates now throw this error "variable template file names not allow within {block} tags".
I was using it for a gridview to allow my to set a template for each column of the view.
{{block name="gridview"}}
Code: |
{{foreach $gridData.rows as $row}}
<tr>
{{foreach $row.template_columns as $cell}}
{{include file=$cell.cell_template_file}}
{{/foreach}}
</tr>
{{/foreach}}
{{/block}}
|
This was very convenient. What can I do instead? |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Thu Oct 10, 2013 11:38 pm Post subject: |
|
|
Included templates could also contain {block} tags. As inheritance is currently a compile time process it could not work with variable file names.
If your included templates don't contain {block} as workaround until a better solution has been found you can comment out lines 138 to 140 in file smarty_internal_compile_include.php |
|
Back to top |
|
UnstoppableCarl Smarty n00b
Joined: 10 Oct 2013 Posts: 3
|
Posted: Fri Oct 11, 2013 1:40 pm Post subject: |
|
|
My included files do not contain any block templates. Are you positive they will work without any problems provided the included files do not contain any blocks? |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Fri Oct 11, 2013 2:05 pm Post subject: |
|
|
If you have no {block} tags in your included subtemplate it is save to suppress the error and comment the corresponding lines out. |
|
Back to top |
|
Yetti Powered Smarty n00b
Joined: 11 Oct 2013 Posts: 1
|
Posted: Fri Oct 11, 2013 3:29 pm Post subject: |
|
|
We also get the same error, after upgrading to the same version of smarty as the original poster (3.1.15).
While we are not using variable template names we are passing variables (strings and arrays) to an included template.
Using the following code.
Code: | {extends file="sitewide/layout.tpl"}
{block "content"}
<ul class="breadcrumb">
<li><a href="{$site.baseUrl}/{$section.urlName}/">{$section.name}</a></li>
{include file="sitewide/breadcrumbLoop.tpl" url="/`$section.urlName`/`$page.urlName`/" data=$itemListing.hierarchy}
</ul>
{/block}
|
Its the URL and data parameters inside the include tag that are causing the problem. For now we have rolled back to version 3.1.14 but does anyone know if this is something that is likely to be fixed shortly? |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Sat Oct 12, 2013 9:53 am Post subject: |
|
|
I'm working it. The fix should be ready over the weekend. |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Sun Oct 13, 2013 12:49 pm Post subject: |
|
|
The fix is now in the SVN trunk and will later be included in 3.1.16 |
|
Back to top |
|
cpeeler Smarty n00b
Joined: 06 Dec 2013 Posts: 1
|
Posted: Fri Dec 06, 2013 6:12 pm Post subject: Also cannot include cached templates in inherited templates |
|
|
Given the following:
Code: |
{extends file="master.tpl"}
{block name="body"}
{include file="file.tpl" cache_id=$cache_id}
{/block}
|
It will not load the cached file.tpl
After digging through code (3.1.15) I found that it's including the file.tpl as a merged/inline template.
I was able to resolve the issue by removing the " || $compiler->inheritance" on line 162 of smarty_internal_compile_include.php (there are two blocks starting with $merge_compiled_includes || $compiler->inheritance, I removed it from the second one.) |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Sat Dec 07, 2013 11:06 am Post subject: |
|
|
cpeeler
Your patch will work only safe if file.tpl does not contain {block} tags.
Smarty 3.1 has a couple of restrictions with none standard {include} with {block} tags like variable template names, individual cache_id's and other. This is because inheritance is in Smarty 3.1 a compile time process.
These restrictions will be removed in the future version 3.2 |
|
Back to top |
|
dlane Smarty n00b
Joined: 12 Dec 2013 Posts: 1
|
Posted: Thu Dec 12, 2013 3:39 pm Post subject: |
|
|
I was just bitten by this. The include file {$variable_name} is a must have for a site I have, so I had to comment the line out of the compile file as stated and now it works. I hope a real fix is coming soon. |
|
Back to top |
|
posttoast Smarty Rookie
Joined: 15 Apr 2008 Posts: 15
|
Posted: Tue May 06, 2014 3:27 pm Post subject: |
|
|
U.Tews wrote: | The fix is now in the SVN trunk and will later be included in 3.1.16 |
I am on 3.1.18 now and have this exact same problem. Was it fixed or not? The 3.1.16 changelog says it is, but I am still getting this error:
Quote: |
variable template file names not allow within {block} tags
|
This is the piece of code that is giving me the problem:
Code: |
{include file="homeblock-`$block.type`.tpl"}
|
|
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Tue May 06, 2014 8:43 pm Post subject: |
|
|
Please read the 3.1.16 release notes. |
|
Back to top |
|
kabal Smarty n00b
Joined: 16 Jun 2014 Posts: 1
|
Posted: Mon Jun 16, 2014 12:12 am Post subject: |
|
|
U.Tews wrote: | Please read the 3.1.16 release notes. |
I've read the release notes from 3.1.16, and I do not see a suggestion on how to migrate code that uses variable template file names within block tags. I'm still seeing the behavior on 3.1.18, so I need to find a solution. |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Tue Jun 17, 2014 5:36 am Post subject: |
|
|
Set $smarty->inheritance_merge_compiled_includes = false;
You must delete the existing compiled and cache files after this modification. The files must be rebuild. |
|
Back to top |
|
TilmP Smarty Rookie
Joined: 04 Aug 2014 Posts: 8
|
Posted: Mon Aug 04, 2014 12:45 pm Post subject: |
|
|
Hello, we also would like to update from SMARTY 3.14 to 3.19.
We use a lot template includes like:
{block name="body"}
{if $LAYOUT.HTML}{include "modules/{$TABS.ACTIVE}/{$LAYOUT.HTML}.html"}{/if}
{/block}
to avoid message as mentioned in the thread
(e.g. Exception: Syntax error in template "styles\default\templates\common\layout.html" on line 164 "{if $LAYOUT.HTML}{include "modules/{$TABS.ACTIVE}/{$LAYOUT.HTML}.html"}{/if}" variable template file names not allow within {block} tags).
I tried to use inheritance_merge_compiled_includes = false. But somehow error is returned
PHP Notice: in file Smarty-3.1.19/sysplugins/smarty_internal_templatebase.php(157) : eval()'d code on line 86: Undefined index: SIDEMENU
How can I fix this? |
|
Back to top |
|
|