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

Undefined index when including dynamic templates

 
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 -> Bugs
View previous topic :: View next topic  
Author Message
kayalion
Smarty n00b


Joined: 08 Dec 2014
Posts: 2

PostPosted: Mon Dec 08, 2014 8:28 pm    Post subject: Undefined index when including dynamic templates Reply with quote

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


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

PostPosted: Mon Dec 08, 2014 11:03 pm    Post subject: Reply with quote

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


Joined: 08 Dec 2014
Posts: 2

PostPosted: Tue Dec 09, 2014 1:17 am    Post subject: Reply with quote

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 Confused

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


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Tue Dec 09, 2014 8:04 am    Post subject: Reply with quote

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


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

PostPosted: Tue Dec 09, 2014 10:46 pm    Post subject: Reply with quote

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
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 -> Bugs 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