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

assigning variable within an array

 
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
gordonisnz
Smarty Regular


Joined: 05 Sep 2009
Posts: 70

PostPosted: Sat Sep 12, 2020 12:41 pm    Post subject: assigning variable within an array Reply with quote

assigning to array value ?

Hi, Is there a trick to assigning an array within a Smarty template ?

I am getting an error in my logs :-

Quote:

Undefined index: Title in


The compiled code looks like this :-

Code:

if (!isset($_smarty_tpl->tpl_vars['v']->value['Title'])) {
$_smarty_tpl->_assignInScope(((string)$_smarty_tpl->tpl_vars['v']->value).".Title", '');
}?>


Source code :-

Code:

 {foreach from=$legislation key=k item=v}
{if !isset($v.Title)}{assign var=$v.Title value=""}{/if} <<< ERROR

{$v.Title}  <<< Then i display it in the htmnl output a few lines down..


Basically, if theres no 'Title' I want it to assign it to a blank entry to avoid the error..

I can assign to a single variable, but havnt done to a variable within an array before.. i do not need it to be a permanent assignment - Just for this loop to get rid of the error.

If title wasnt set - it caused an error to be logged. (but not visible to the public)
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Thu Sep 24, 2020 9:24 am    Post subject: Reply with quote

Code:
{foreach $legislation as $k => $v}
{$v= $v + ["Title" => "x"]}
{$v|print_r:true}
{$v.Title}
{/foreach}
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
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