Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.
extends tag does not allow variables or expressions anymore.

 
Post new topic   Reply to topic    Smarty Forum Index -> General
View previous topic :: View next topic  

Do you use variables or expressions inside extends tag?
Yes
100%
 100%  [ 4 ]
No
0%
 0%  [ 0 ]
Total Votes : 4

Author Message
sectus
Smarty n00b


Joined: 02 Oct 2013
Posts: 3

PostPosted: Wed Oct 02, 2013 1:39 am    Post subject: extends tag does not allow variables or expressions anymore. Reply with quote

After upgrading to 3.1.15 I have got error message.

Code:
Smarty Compiler: Syntax error in template ".../templates/child.tpl" on line 1 "[{extends file=$parent_tpl }]" variable template file name not allowed.


So, as i can see here,I cannot use variables and expressions with in extends tag anymore, only plain string.

I am using consts, expressions and variables (documentation still allow it).

Why it was changed? How can I achieve dynamic extending?
Back to top
View user's profile Send private message
U.Tews
Administrator


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

PostPosted: Thu Oct 03, 2013 10:09 am    Post subject: Reply with quote

Actually it was a bug to allow variables in the {extends } tag.

Template inheritance is a compile time process where the code of child and parent templates is merged in one compiled template file.
Smarty did compile your template correctly on the first call using the variable {extends} tag but did ignore any changes of the variable on later calls because the name of the compiled template file could only be determined from the name of the child template.
So always the same code compiled off the first run got loaded.

To use variable template names use the extends: resource instead.

Example
Code:

$foo = 'foo.tpl';
$smarty->display("extends:bar.tpl|$foo");


The extends resource is able to build the compiled template file name based on all child/parent source template names.

This restriction will be removed in the future major release 3.2 I#m working on.
Back to top
View user's profile Send private message
sectus
Smarty n00b


Joined: 02 Oct 2013
Posts: 3

PostPosted: Fri Oct 04, 2013 2:18 am    Post subject: Reply with quote

Documentation still has it.

It was very useful inl my case is:

[{extends file=$smarty.const.PATH_SYSTEM_TEMPLATES|cat:"/show.tpl" }]

But thanks for advice.
Back to top
View user's profile Send private message
U.Tews
Administrator


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

PostPosted: Fri Oct 04, 2013 8:53 am    Post subject: Reply with quote

Oh, variable {extends} have been disabled by mistake. It can be used when using different compile_id's as mentioned in documentation.

It's reenabled in the SVN trunk version.
Back to top
View user's profile Send private message
sectus
Smarty n00b


Joined: 02 Oct 2013
Posts: 3

PostPosted: Thu Jan 09, 2014 8:24 am    Post subject: Reply with quote

Works with Smarty 3.1.16 with

Code:
       
$Smarty->inheritance_merge_compiled_includes  = false;
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