Page 1 of 1

Stop print_r from printing 1's

Posted: Tue Mar 25, 2014 9:13 am
by wmdvanzyl
I was wondering whether there is a way to stop the print_r function from printing 1's all over the place. I assume it is the "true" value it returns after completing successfully. I was wondering if there is a way around this or perhaps there is a better way to debug stuff when you need screen output than print_r?

Any suggestions?

Re: Stop print_r from printing 1's

Posted: Tue Mar 25, 2014 10:34 am
by zaidcrowe
Re the '1' this can happen for a coupla reasons, say a function returning true, or if you do it against an array (i think) it can mean that the array is set, but has no values

Have you tried {debug} or {get_template_vars} ...? Think both of these are documented in the tags section of the cms

Re: Stop print_r from printing 1's

Posted: Tue Mar 25, 2014 12:10 pm
by velden
Or use it in html comment, so your visitors don't see it while you're debugging (unless they look in source).

End you don't need the <pre> tags

<!-- {$var|print_r} -->

Re: Stop print_r from printing 1's

Posted: Wed Mar 26, 2014 5:53 am
by wmdvanzyl
Thanks for the feedback.
zaidcrowe wrote:Have you tried {debug} or {get_template_vars} ...? Think both of these are documented in the tags section of the cms
I do use those, but there are times you just need to print_r something to the screen. :) Where i got confused was when the output of print_r was actually 1, but i couldn't see it amongst all the 'other' 1's :D
velden wrote:<!-- {$var|print_r} -->
That's smart, but in this case it wasn't the output to end users that needed to be altered, but rather the output i get. If, for example, i output a variable which has a value of 1, i tend to miss it and think that it is blank, because there are so many 1's floating around. :)

Re: Stop print_r from printing 1's

Posted: Wed Mar 26, 2014 10:07 am
by Jo Morg
Try:

Code: Select all

{$var|print_r:true}

Re: Stop print_r from printing 1's

Posted: Wed Mar 26, 2014 10:35 am
by zaidcrowe
nice! i didnt know about this - some greeat discussion around this here: http://www.smarty.net/forums/viewtopic.php?p=16128