Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.
variable template file names not allow within {block} tags

 
Post new topic   Reply to topic    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: 4509
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: 4509
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: 4509
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: 4509
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: 4509
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
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
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