bytesource Posted December 2, 2012 Share Posted December 2, 2012 Hi Everyone, I have a page with the following template: product.php <h1><?php echo $page->title; ?></h1> <p><?php echo $page->introduction; ?></p> <?php $children = $page->children; if(count($children)) { foreach($children as $item) { echo $item->render(); // output template associated with item page } } ?> <br style='clear: both;' /> that renders one or more child pages: item.php <h2><?php echo $page->title; ?></h2> <p><?php echo $page->introduction; ?></p> These child pages are not supposed to be accessed by their URL, as they only provide content and markup to the parent page. Setting them to hidden does not work, because then they won't be found as children anymore. I could just use a no_file template and then add the markup for the child pages directly to the parent's template file (product.php), but I prefer to keep this markup in a separate file. Is there a way to solve this problem? Any suggestions are highly welcome! Link to comment Share on other sites More sharing options...
Martijn Geerts Posted December 2, 2012 Share Posted December 2, 2012 IF you set them to hidden you could do: <h1><?php echo $page->title; ?></h1> <p><?php echo $page->introduction; ?></p> <?php $children = $page->children('include=all'); if(count($children)) { foreach($children as $item) { if ($item->isHidden()) { echo "I'm not displayed."; } else { echo $item->render(); // output template associated with item page } } } ?> <br style='clear: both;' /> (ps, written in browser not tested) 1 Link to comment Share on other sites More sharing options...
bytesource Posted December 2, 2012 Author Share Posted December 2, 2012 Hi Martijn, Thanks a lot for your help! Your suggestion reminded me to take a closer look at the Selectors API. There I found 'include=hidden', which might be an even better fit for my use case. Using this selector, unpublished pages won't be included. By the way, do you if there is a way to set all pages that are attached to a certain template to be hidden (or any other status) by default? Link to comment Share on other sites More sharing options...
ryan Posted December 2, 2012 Share Posted December 2, 2012 By the way, do you if there is a way to set all pages that are attached to a certain template to be hidden (or any other status) by default? There isn't a setting to do that, but you can accomplish it pretty easily from a selector: $page->children("template!=some_template"); $pages->find("template!=some_template|some_other_template"); Or, even better, specify the template you want: $pages->find("template=good_template"); Link to comment Share on other sites More sharing options...
bytesource Posted December 3, 2012 Author Share Posted December 3, 2012 Thanks Ryan, your answer helped me a lot! 1 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