Jump to content

Recommended Posts

Posted

I've got a PageTable field and added several templates (intro, gallery, text, etc.). But how do I get those templates rendered? I can't find any docs and feel like revolving from the forum to the store.

Anyhow. Perhaps someone can help. I have my basic-page.php with the PageTable field and its (sub-)pages. For example the gallery. I created the gallery.php file and now I struggle to get the code from my gallery template to show in my page.

Or in other words …

Page: Team (basic-page.php)
basic-page.php has PageTable field
PageTable field has a block_gallery template
block_gallery.php has the code to show the gallery
… how can I show the gallery on the Team page?

Posted (edited)

Have you tried something like this?

$out = '';
foreach($page->page_table_field as $p) {
         $out .= $p->render();
}
echo $out;

Of course, change $page as needed

Edited by kongondo
  • Like 2
Posted

Yes, I found it just a minute ago. Was searching a whole hour before! :-) 

But, what about the docs? There is no documentation for that field?

// … ohh … and thanks a lot!

Posted

Using render() as kongondo suggests is good - here is some info from Ryan on the available options.

But I usually output from a PageTable the same way as I would a Repeater, e.g. if page_table_field is in the "basic page" template, in basic-page.php...

foreach($page->page_table_field as $p) {
    echo "<h3>{$p->title}</h3>";
    // etc, for other fields in the PageTable item template
}

 

  • Like 1
Posted

Thanks Robin. I would do like you, but I've quite a lot of templates and all of them are totally different. It's more manageable for me to put them into their own templates.  However, thanks for the code! And thanks for the link. But I had more of an "how to use PageTable" doc in mind. Seems there is no dedicated documentation for it.

Posted

Ok, that makes things a little bit more complicated (at least for me). 

There is currently one more question in my head.

How do I access page variables of the containing page? When using $page->parent->title I get the page in the Admin tree, not the page containing with the page table.

Posted
1 hour ago, suntrop said:

How do I access page variables of the containing page?

You pass $page to the render method in the $options array.

From the post I linked to above:

Quote

If you made this render() call:


echo $page->render('myfile.php', array('foo' => 'bar')); 

myfile.php could access the 'foo' variable like this:


echo $options['foo']; // outputs "bar"

 

 

  • Like 2
Posted
21 hours ago, suntrop said:

But, what about the docs? There is no documentation for that field?

That's because PageTables do not have any kind of field-specific api. They're just another form of page field. 

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
  • Recently Browsing   0 members

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