Question

so I have one associative array {$join_options} with five entries already in it.

if I dump $join options it will show:

19 => Some text for 19
20 => Some text for 20
22 => Some text for 22
24 => Some text for 24
26 => Some text for 26

Good so far.

And if I just use {$join_options.20} it will print

Some text for 20

But then I try this little ditty:

{assign var=modified_join_options values=[
20 => '$join_options.20',
24 => '$join_options.24',
26 => '$join_options.26',
]}

and I get this error:

syntax error: invalid attribute name: ''$join_options.20',' (Smarty_Compiler.class.php, line 1550)

I've tried multiple different ways to type $join_options.20 I've tried with '' without with {} and without Wat do?

EDIT: I've tried adding backticks, using value instead of values, removing the last comma. Now I get:

Smarty error: [in site:join line 116]: syntax error: invalid attribute name: '=' (Smarty_Compiler.class.php, line 1550)

Was it helpful?

Solution 3

So, I wound up just creating a function for smarty where I passed in the smarty object and the arrays as params. Inside the function of the plugin I do my manipulation and then use the smarty object to assign the options i want to a new array using foreach key value loops, if statements, strpos() and strtolower() functions. Pretty standard php stuff. I don't know if this is standard procedure for smarty but I found some helpful documentation with the software I am using and it informed that this was an option.

OTHER TIPS

It's because it has a . in it. You have to surround the variable with backticks. Try this.

{assign var=modified_join_options values=[
20 => '`$join_options.20`',
24 => '`$join_options.24`',
26 => '`$join_options.26`',
]}

http://www.smarty.net/docsv2/en/language.syntax.quotes.tpl

Use value, remove the quotes and the last comma and it will work:

{assign var=modified_join_options value=[
20 => $join_options.20,
24 => $join_options.24,
26 => $join_options.26
]}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top