suntrop Posted January 30, 2017 Share Posted January 30, 2017 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? Link to comment Share on other sites More sharing options...
kongondo Posted January 30, 2017 Share Posted January 30, 2017 (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 January 30, 2017 by kongondo 2 Link to comment Share on other sites More sharing options...
suntrop Posted January 30, 2017 Author Share Posted January 30, 2017 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! Link to comment Share on other sites More sharing options...
Robin S Posted January 30, 2017 Share Posted January 30, 2017 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 } 1 Link to comment Share on other sites More sharing options...
suntrop Posted January 30, 2017 Author Share Posted January 30, 2017 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. Link to comment Share on other sites More sharing options...
Robin S Posted January 30, 2017 Share Posted January 30, 2017 1 minute ago, suntrop said: Seems there is no dedicated documentation for it. Nope Link to comment Share on other sites More sharing options...
suntrop Posted January 31, 2017 Author Share Posted January 31, 2017 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. Link to comment Share on other sites More sharing options...
Robin S Posted January 31, 2017 Share Posted January 31, 2017 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" 2 Link to comment Share on other sites More sharing options...
LostKobrakai Posted January 31, 2017 Share Posted January 31, 2017 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. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now