Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

variable template file names not allow within {block} tags
Goto page 1, 2  Next
 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
UnstoppableCarl
Smarty n00b


Joined: 10 Oct 2013
Posts: 3

PostPosted: Thu Oct 10, 2013 3:11 pm    Post subject: variable template file names not allow within {block} tags Reply with quote

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
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Thu Oct 10, 2013 11:38 pm    Post subject: Reply with quote

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
View user's profile Send private message
UnstoppableCarl
Smarty n00b


Joined: 10 Oct 2013
Posts: 3

PostPosted: Fri Oct 11, 2013 1:40 pm    Post subject: Reply with quote

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
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Fri Oct 11, 2013 2:05 pm    Post subject: Reply with quote

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
View user's profile Send private message
Yetti Powered
Smarty n00b


Joined: 11 Oct 2013
Posts: 1

PostPosted: Fri Oct 11, 2013 3:29 pm    Post subject: Reply with quote

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
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Sat Oct 12, 2013 9:53 am    Post subject: Reply with quote

I'm working it. The fix should be ready over the weekend.
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Sun Oct 13, 2013 12:49 pm    Post subject: Reply with quote

The fix is now in the SVN trunk and will later be included in 3.1.16
Back to top
View user's profile Send private message
cpeeler
Smarty n00b


Joined: 06 Dec 2013
Posts: 1

PostPosted: Fri Dec 06, 2013 6:12 pm    Post subject: Also cannot include cached templates in inherited templates Reply with quote

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
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Sat Dec 07, 2013 11:06 am    Post subject: Reply with quote

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
View user's profile Send private message
dlane
Smarty n00b


Joined: 12 Dec 2013
Posts: 1

PostPosted: Thu Dec 12, 2013 3:39 pm    Post subject: Reply with quote

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
View user's profile Send private message
posttoast
Smarty Rookie


Joined: 15 Apr 2008
Posts: 15

PostPosted: Tue May 06, 2014 3:27 pm    Post subject: Reply with quote

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
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Tue May 06, 2014 8:43 pm    Post subject: Reply with quote

Please read the 3.1.16 release notes.
Back to top
View user's profile Send private message
kabal
Smarty n00b


Joined: 16 Jun 2014
Posts: 1

PostPosted: Mon Jun 16, 2014 12:12 am    Post subject: Reply with quote

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
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Tue Jun 17, 2014 5:36 am    Post subject: Reply with quote

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
View user's profile Send private message
TilmP
Smarty Rookie


Joined: 04 Aug 2014
Posts: 8

PostPosted: Mon Aug 04, 2014 12:45 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
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
Protected by Anti-Spam ACP