Page 1 of 1

[SOLVED] Referencing associative arrays (spaces in keys) ...

Posted: Mon Dec 05, 2011 2:38 am
by spcherub
I use the following code to reference an associative array (in this case in the News module detail template):

Code: Select all

$entry->fields.TestField->value
However I am not able to use this syntax to reference another value where the key has a space in it, like:

Code: Select all

$entry->fields.Article Author->value
Smarty throws an error in this case.

I've tried various tricks like:
- $entry->fields."Article Author"->value
- Assigning the key name to a variable and using eval
- Using capture to assign the variable value and then using eval

Does anyone know how this can be done in Smarty? Without this, the only way to access a custom field in the latest News module is to run a foreach loop and check for the name of the desired field - that seems long-winded.

TIA
-S

Re: Referencing associative arrays (spaces in keys) in smart

Posted: Mon Dec 05, 2011 3:09 am
by Wishbone
{assign var=index value="Article Index"}
$entry->fields.$index->value

Re: Referencing associative arrays (spaces in keys) in smart

Posted: Mon Dec 05, 2011 3:23 am
by spcherub
Thanks - I tried that before, but it did not work. After your reply, I went back and looked and realized that I had forgotten to make that custom field "Public" in the news module which is why I was getting no results!

I feel really silly now!

Thanks,
-S