PDA

View Full Version : template variable print_r/var_dump


johnobandalong
03-06-2006, 10:51 PM
Is there a way to dump out all variables that is available at the template level?

If not, is there at least a way to use print_r/var_dump inside a template?

merk
03-07-2006, 02:13 AM
Yes and No. (use hooks prior to template call or modify fetch_template to instead of echoing out the template, it does a print_r call.)

It would be easier to look at where the template is called from and work out template scope from there.

rossco_2005
03-07-2006, 02:28 AM
Best idea I can come up with is a plugin that sets a variable with your vardump like this:
$var = print_r($var,true);

then put $var into your template.

merk
03-07-2006, 02:59 AM
That wont work. print_r prints directly to stdout.

You would need to use output buffering at the very least, and variable scope could change between the plugin and the template.

johnobandalong
03-07-2006, 04:18 PM
Thanks for the info guys but I was hoping there was a debug mode for the template (ex. smarty's debug mode) that prints out all variables at the template scope.

This way I dont have to know the variable name in order to find what I'm looking for.

Adrian Schneider
03-07-2006, 04:43 PM
If you want to print_r to a variable, use "print_r($var, true)" the second arguement makes it return instead of echo/print it.

I always just do it in the file I'm working on (which is usually a custom file, not a vB file... even if it is a vB file, just put it back after because that is MUCH easier than working with plugins for debug code).

Try using vBulletin's print_r function. I think it is is functions_misc.php (either print_array() or print_ar(). It is a formatted version of print_r.

merk
03-07-2006, 09:06 PM
Didnt know that one, thanks :)

As for a template debug mode, just modify the function temporarily.

Paul M
03-07-2006, 09:17 PM
you can also just use print_r($array); exit;

Then the results will be viewable with nothing else clogging the screen.

Adrian Schneider
03-10-2006, 02:40 AM
you can also just use print_r($array); exit;

Then the results will be viewable with nothing else clogging the screen.
I usually do that, though I created a few simple functions to include when testing something. Basically they include the <pre> tags, and an optional parameter to exit the script.

Whatever makes debugging faster is good! :)