php - smarty grammer error cannot use symbol [] -


this line:

{$data["bank_data"]["arrangement"]["id"]} 

returns following error:

php (5.3.9) error (e_user_error):
file: smarty.class.php
line: 1092
type: smarty error: [in tke-g-admin_scopeofwork.tpl line 10]: syntax error: unrecognized tag: $data["bank_data"]["arrangement"]["id"] (smarty_compiler.class.php, line 446)

this line:

{$data.bank_data.arrangement.id} 

does not return error. works correctly.

so, why first section wrong? how use [] access array.

judging error posted, you're using smarty2. the docs give 2 options accessing arrays:

{* string indexes *} {$some.array.value} {* numeric indexes *} {$some[0][1]} 

you can use variable provide index so

{assign var="key" value="array"} {$some.$key.value} == {$some.array.value} 

using "trick", can access string indexes containing "special characters" such ., [] or .


smarty3 bit more flexible in way:

{$some.{"hello world"}.array["array"]['foo']} 

oddly enough {$foo[bar]} not parsed (in smarty 3.1.10). threw on todo list, though.


Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -