PHP Coding Tips

Tuesday, August 7, 2012

print_r in smarty - How to print your array contents in smarty template.

You can print a array contents like in php print_r() function in smarty tempalte. The common mistake is to forget about second print_r parametr for returning it's output. This parameter have to be set to true. If you forget to set it to true, your array contents propably will be somewhere at begining of a content. This is the solution:
{$myArray|@print_r:true}
Notice the @ symbol that provides parsing argument as array, not as string.

28 comments:

  1. Enter your comment here..

    ReplyDelete
  2. Why do I see this:
    Fatal error: Call to undefined function smarty_modifier_print_r()

    ReplyDelete
  3. Thank you very much. working like charm

    ReplyDelete
  4. thanks.. i have been looking for answer as to why {$combo.title|@print_r} .. seems not to work.. i will give this a try and come back later..

    ReplyDelete
  5. Awesome! Education is the extreme motivation that open the new doors of data and material. So we always need to study around the things and the new part of educations with that we are not mindful.
    DevOps Training | Certification in Chennai | DevOps Training | Certification in anna nagar | DevOps Training | Certification in omr | DevOps Training | Certification in porur | DevOps Training | Certification in tambaram | DevOps Training | Certification in velachery

    ReplyDelete
  6. This comment has been removed by the author.

    ReplyDelete
  7. This is an awesome post.Really very informative and creative contents. These concept is a super way to enhance the knowledge.I like it and help me to development very well.Thank you for this brief explanation and very nice information.Well, got a good knowledge.


    Java training in Chennai

    Java training in Bangalore

    Java training in Hyderabad

    Java Training in Coimbatore

    Java Online Training

    ReplyDelete