|
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 |
kayalion Smarty n00b
Joined: 08 Dec 2014 Posts: 2
|
Posted: Mon Dec 08, 2014 8:28 pm Post subject: Undefined index when including dynamic templates |
|
|
Hello,
I'm trying to include dynamic templates and can't get it to work. It always tells me undefined index on the variable of the file argument. Seems like a bug to me ...
To reproduce, install the latest Smarty through composer and add following files:
index.php
Code: |
<?php
include __DIR__ . '/vendor/autoload.php';
$smarty = new Smarty();
$smarty->assign('templates', array('foo' => 'foo.tpl'));
$smarty->assign('templateIndex', 'foo');
$smarty->display('index.tpl');
|
index.tpl
Code: |
{block name="layout"}
{* works *}
{include file=$templates.$templateIndex inline}
{* does not work *}
{$index = 'foo'}
{include file=$templates.$index inline}
{* does not work and what I need to do *}
{foreach $templates as $index => $template}
{include file=$templates.$index inline}
{/foreach}
{/block}
|
foo.tpl
Code: |
<strong>foo</strong>
|
Can somebody help me?
Thanks! |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Mon Dec 08, 2014 11:03 pm Post subject: |
|
|
Remove the 'inline' option in {include}.
Merging compiled templates by using the 'inline' option or setting $smarty->merge_compiled_includes = true; is a compile time process and does not work on variable subtemplates as you could call any template at run time.
Smarty does detect variable subtemplates automatically and excludes them.
So setting the 'inline' option on variable subtemplates is useless.
The bug that you get a notice was already fixed in the 'dev' version.
Until 3.1.22 will be released you can get it with
"smarty/smarty": "~3.1@dev" |
|
Back to top |
|
kayalion Smarty n00b
Joined: 08 Dec 2014 Posts: 2
|
Posted: Tue Dec 09, 2014 1:17 am Post subject: |
|
|
Thanks for your quick answer!
I did an update to the dev and this seems to work. I still need to add the inline option since I'm in a block.
The update did bring up some issues though
When I do:
Code: | {foreach $values as $key => $null} |
The compiler crashes on the null, minor but seems a bug to me.
Code: |
{function sme}
{/function}
{$functionName = 'sme'}
{call $functionName}
|
This also seems to be broken
I used to run 3.1.16 and that version did not have any problems with these. Any idea?
Do you know a release date for 3.1.22?
Much obliged |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Tue Dec 09, 2014 8:04 am Post subject: |
|
|
U.Tews wrote: | Merging compiled templates by using the 'inline' option or setting $smarty->merge_compiled_includes = true; is a compile time process and does not work on variable subtemplates as you could call any template at run time.
Smarty does detect variable subtemplates automatically and excludes them. |
Does that alo work, if I include=inline parent template? |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Tue Dec 09, 2014 10:46 pm Post subject: |
|
|
The template variables $null, $true, $false did fail after adding namespace support on 12.11.2014.
I missed the fact that PHP does implement null, true and false as constants.
The fix is now in the github 'dev' version.
Thank's for pointing it out.
Edit:
It will need another update which will follow tomorrow. |
|
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
|