|
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 |
gordonisnz Smarty Regular
Joined: 05 Sep 2009 Posts: 70
|
Posted: Sat Sep 12, 2020 12:41 pm Post subject: assigning variable within an array |
|
|
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 |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Thu Sep 24, 2020 9:24 am Post subject: |
|
|
Code: | {foreach $legislation as $k => $v}
{$v= $v + ["Title" => "x"]}
{$v|print_r:true}
{$v.Title}
{/foreach}
|
|
|
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
|