SNIPPET: DISPLAY CONTENTS OF SMARTY ARRAY

Snippet: Display Contents of Smarty Array 
Compatibility
All Versions
Credits
Rating
  • Currently 3.50/5

Rating: 3.5/5
(2 votes cast)

Login to Rate

Sometimes you just need to see what variables are available in an array in Smarty. In PHP this is usually done using print_r($foo) where $foo is your array. But in smarty this is done using the following method.

{$foo|@print_r}

When you use this command I recommend placing open and closing pre tags around the command to ensure the output is formatted in a readable format.

The @ tells smarty to pass the entire array to the modifier rather than calling the modifier for each element of the array. Smarty also ships with a modifier that does similar to print_r(): {$foo|@debug_print_var}. You may also consider Smartys debug facility (which you can enable in-template by inserting a {debug} tag or you can enable by configuring the Smarty object appropriately - see the docs for more info)

{$foo|@print_r}
Replace $foo with a smarty array.

ID: 91 | CAT: 19
 
Danish BackerMarch 22, 2011 Reply

Thanks for sharing :)

Comment / Reply



Emails will not be published or shared. If you have a Gravatar account - the avatar image associated with your email address will appear. Please note, all comments are moderated, so be nice.



Like this comments mod? Get it here

There have been no reviews/comments yet

Please login to leave a comment/review
Name: *
Email: *
Telephone:  
Question(s): *
Code:  
Enter Code: *
    Submit
Your name
Your email
Recipient's email
  Send to friend
 X 

You added a product to the cart!

View cart

Checkout

Back to products

Close

PayPal Accepted