|
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: Tue May 25, 2021 11:41 am Post subject: Trouble assigning SUB array |
|
|
Hello. Is there a good example of how to assign a SUB array within a smarty template ?
PHP code :-
Code: | $array["family"]["Jones"]["name"]="bob"; |
But I want to do this within Smarty template (the array "family" doesn't exist at all. )
All the codes / examples i see online assume you only want to assign a top-level array - But I cannot find any examples for sub-arrays.
I've tried a few combinations EG :-
Code: | {if !(isset($outerform.$k.TYPEOPTION))}{assign $outerform[$k]["TYPEOPTION"]=""}{/if} |
Can anyone give me JUST the smarty template coding. Thanks. |
|
Back to top |
|
gordonisnz Smarty Regular
Joined: 05 Sep 2009 Posts: 70
|
Posted: Thu May 27, 2021 5:33 am Post subject: |
|
|
Has anyone got a solution ?
Ive fixed my original problem - but now gettinG UNDEFINED INDEX TYPEOPTION
Code: |
{if !(isset($outerform.$k.TYPEOPTION))}{assign $outerform.$k.TYPEOPTION value=""}{/if}
|
THAT is why im testing for it - if its not set - then set it.
Why am i getting the error ?
Quote: |
[27-May-2021 17:28:36 Pacific/Auckland] PHP Notice: Undefined index: TYPEOPTION in .....
|
The template has only 3 lines where TYPEOPTION exists & the first line is setting it if it doesnt exist. |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Sun May 30, 2021 8:02 am Post subject: |
|
|
I don't understand your problem.
Code: | PHP: {$smarty.const.PHP_VERSION}
Smarty: {$smarty.version}
{$arr['x']['y']['z']="t"}
{$arr|print_r:true}
|
Code: | PHP: 7.4.16
Smarty: 3.1.36
Array
(
[x] => Array
(
[y] => Array
(
[z] => t
)
)
) |
If you only want to set it if it's not set, then
Code: | PHP: {$smarty.const.PHP_VERSION}
Smarty: {$smarty.version}
{$arr['x']['y']=['z' => 't']}
{* Assign only if not set *}
{$arr['x']['y']=$arr['x']['y'] + ['z' => "d"]}
{$arr|print_r:true} |
|
|
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
|