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

The place to talk about things that are related to CMS Made simple, but don't fit anywhere else.
Post Reply
spcherub
Power Poster
Power Poster
Posts: 402
Joined: Fri Jun 06, 2008 5:54 pm

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

Post 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
Last edited by spcherub on Mon Dec 05, 2011 3:23 am, edited 1 time in total.
Wishbone
Power Poster
Power Poster
Posts: 1368
Joined: Tue Dec 23, 2008 8:39 pm

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

Post by Wishbone »

{assign var=index value="Article Index"}
$entry->fields.$index->value
spcherub
Power Poster
Power Poster
Posts: 402
Joined: Fri Jun 06, 2008 5:54 pm

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

Post 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
Post Reply

Return to “The Lounge”