Jump to content

How to use print_r to see available settings?


OpenBayou
 Share

Recommended Posts

Hey,

I'm trying to find a way to see what variables are available using 'print_r' but I get a blank page. This is the code I'm using so far:

<?php foreach($pages->find("parent=recommendations") as $child) { ?>
	<?php echo $child->title;?>
	<img src="<?php echo $child->post_image->first()->size(200,0)->url;?>">
<?php } ?>

I just want to see what's available in $child. When I try to do 'print_r($child)`, I get a blank page. Like a white screen of death. This is what I have so far:

<?php foreach($pages->find("parent=recommendations") as $child) { ?>
	<?php echo $child->title;?>
	<img src="<?php echo $child->post_image->first()->size(200,0)->url;?>">
	<pre>
	<?php print_r ($child);?>
	</pre>
<?php } ?>

Thanks for the help.

Link to comment
Share on other sites

Tracy to the rescue:

<?php foreach($pages->find("parent=recommendations") as $child) { ?>
    <?php echo $child->title;?>
    <img src="<?php echo $child->post_image->first()->size(200,0)->url;?>">
    <?bd($child);?>
<?php } ?>

But that said, I really don't know what you mean by: "see what variables are available". If we knew more we could tweak what the bd() call will dump.

Are you wanting to get a list of fields on the child pages? Do you mean actual template variables defined for each page? I really don't know.

Also, I know you might be used to that style of going in and out of PHP, but when there is more php than html, this reads much nicer:

<?php
foreach($pages->find("parent=recommendations") as $child) {
    echo $child->title;
    echo '<img src="'.$child->post_image->first()->size(200,0)->url.'" />';
    bd($child);
}

 

Link to comment
Share on other sites

Quote

Are you wanting to get a list of fields on the child pages? Do you mean actual template variables defined for each page? I really don't know.

Yes on both. I'm new at ProcessWire and I'm just looking to see what's available.

Link to comment
Share on other sites

2 minutes ago, OpenBayou said:

Yes on both. I'm new at ProcessWire and I'm just looking to see what's available.

Check out the PW Info and Template Resources panels in Tracy. Those will show all sorts of info on the contents of fields (and their settings) as well as the variables you have defined manually in your templates.

Screen Shot 2017-01-06 at 10.16.51 PM.png

Screen Shot 2017-01-06 at 10.17.16 PM.png

  • Like 1
Link to comment
Share on other sites

Just now, OpenBayou said:

How do I access Tracy? Is it a plugin?

Yes - sorry, I thought I had linked to it earlier: 

Blog post documentation: http://processwire.com/blog/posts/introducing-tracy-debugger/

Forum thread: https://processwire.com/talk/topic/12208-tracy-debugger/

Modules directory: http://modules.processwire.com/modules/tracy-debugger/

  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...