2

Given this in the Smarty template:

<pre>{$user->settings['sendStats']|@print_r:1}</pre>

The output in the browser is this:

Array
(
    ['period'] => daily
    ['ofPeriod'] => year
    ['points'] => 1000
)

Doing any of these:

<pre>{$user->settings['sendStats']['period']|@print_r:1}</pre>
<pre>{$user->settings['sendStats'][ofPeriod]|@print_r:1}</pre>
<pre>{$user->settings['sendStats'].points|@print_r:1}</pre>
<pre>{$user->settings.{'sendStats'}.{'period'}|@print_r:1}</pre>
<pre>{$user->settings.{sendStats}.{period}|@print_r:1}</pre>

with or without the |@print_r:1 gives no output in the browser.

I also tried assigning $user->settings to a Smarty variable and I get the exact same result (as expected).


How do I access the elements of the $user->settings['sendStats'] array?

3 Answers 3

1

{$user->settings.sendStats.period|@print_r:1} should work just fine. Also have a look at the Variables page in the docs…

Sign up to request clarification or add additional context in comments.

Comments

0

The array values itself are not arrays (your array is not multidimensional), so you should drop the |@print_r:1 and you should be fine. Should look something like:

<pre>{$user->settings['sendStats']['period']}</pre>

1 Comment

Did that, but nothing changed. Also, if the values are not array then the print_r would still output them as they are.
0

Finally figured it out. The array keys contained single quotes, so the answer would have been:

{$user->settings['sendStats']["'period'"]}

I fixed it so the keys didn't contain quotes anymore.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.