kaz Posted February 8 Share Posted February 8 I do different content sections with Repeater Matrix. Since there are more and more sections, I would like to choose another solution. I don't have any experience with Page Table, but based on what I've read, it seems like a possible alternative? My repeater matrix script is a foreach, so that the user can extend it as needed. <?php foreach($page->sections as $item) { if($item->type == 'content') { echo " <h1>$item->title</h1> $item->content "; } if($item->type == 'links') { echo " … "; } and so on } I can add the items of the above script as single templates for Page Table, and add them in a Page Table field (Details). In my base template I call the page table field, e.g. echo $page->render('sections'); On my first try, a child page was added, which I don't really want. The code from the template which I had added in the field (details) was not taken over either. In short, I need help. Can perhaps someone give me a little HOWTO on how to do this correctly? Maybe Page Table isn't suitable at all? Link to comment Share on other sites More sharing options...
gmclelland Posted February 8 Share Posted February 8 This tutorial might help? https://processwire.com/talk/topic/27499-something-like-gutenbergdrupal-paragraphs/#comment-226306 2 Link to comment Share on other sites More sharing options...
gebeer Posted February 9 Share Posted February 9 Maybe you want to take a look at https://processwire.com/modules/fieldtype-page-table-extended/ That module hasn't been updated in a while but should have code that can point you in the right direction. Link to comment Share on other sites More sharing options...
bernhard Posted February 9 Share Posted February 9 If you want a solid solution that has seen several years of development and is tailored exactly towards that use case have a look at RockPageBuilder: It will not only make your life as a developer easier, it will also tremendously improve the editing experience for your clients. Try it out yourself at https://pagebuilder.baumrock.com 1 1 Link to comment Share on other sites More sharing options...
markus-th Posted February 9 Share Posted February 9 20 hours ago, kaz said: I do different content sections with Repeater Matrix. Since there are more and more sections, I would like to choose another solution. Look at this idea: Since I have been using this method, I no longer need any other approach to build up the content on my pages and I also need far fewer different templates. You don't have to use depth, but it allows extremely flexible output of content when needed. My basic_page template look like this: <?php namespace ProcessWire; include "_header.php"; $items = $page->content; foreach ($items as $key => $item) { $item->position = $key; $item->all_items = $items; } foreach ($items->find("depth=0") as $item) { echo $item->render(); } include "_footer.php"; And all matrix "content" templates are inside the fields folder. 2 Link to comment Share on other sites More sharing options...
Robin S Posted February 9 Share Posted February 9 9 hours ago, Markus Thomas said: Since I have been using this method, I no longer need any other approach to build up the content on my pages and I also need far fewer different templates. If you like that approach you might like to try the Repeater Depth Helper module which is a development from that earlier idea. It gives you the depth structure for the whole repeater field from one method and also enforces a couple of depth rules to keep things sane. 2 Link to comment Share on other sites More sharing options...
kaz Posted March 2 Author Share Posted March 2 Is there perhaps an official documentation for PageTable? I can't find anything in the forum posts explaining how to render PageTable templates? I placed two templates in the /views folder and inserted them in the Page Table field. The editor can now add the elements of the templates. The section-content is saved on a hidden page which I created separately in the admin area. My nameofpagetablefield does not transfer any data. echo $page->render('nameofpagetablefield'); There is no error, I don't understand where to look? But how do I use foreach to render different items / templates? Link to comment Share on other sites More sharing options...
gmclelland Posted March 3 Share Posted March 3 @kaz I posted a link to a tutorial in my post above. The difference is in that tutorial the templates exists in a “fields” directory and not in a views directory. Rendering fields template files are also described here https://processwire.com/blog/posts/processwire-3.0.7-expands-field-rendering-page-path-history-and-more/#field-rendering-with-template-files 1 Link to comment Share on other sites More sharing options...
kaz Posted March 4 Author Share Posted March 4 @gmclelland I have it in the /views folder, not /fields, because in PageTable I have to select a template. PageTable does not allow to select a folder, so my templates are in the /views folder ? I would prefer to have the widget templates in an own folder, but it's not possible with PageTable. This is the code of my bodysection file (PageTable Field): <?php namespace ProcessWire; // Loop through each element in the PageTable field foreach($bodysection as $section) { // Get the template of the page in the PageTable field $template = $section->template->name; // Depending on template, render the content switch($template) { case 'section-content': // "section-content" template rendered here echo $section->render(); break; case 'section-gallery': // "section-gallery" template rendered here echo $section->render(); break; case 'section-…': // and so on break; } } Only the Page IDs are received in frontend, at least the IDs are correct, yeah: 1122|1124 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