gtoirog Posted July 1, 2013 Posted July 1, 2013 and if I do <?php echo $pages; ?>, it prints only a word "Pages". I don't think I'm getting any page in this variable?! Any idea?
MatthewSchenker Posted July 1, 2013 Posted July 1, 2013 Greetings, What exactly do you want to output? Which pages/fields/data? You have to be more specific. Thanks, Matthew
kongondo Posted July 1, 2013 Posted July 1, 2013 (edited) $pages->find() will find things; lots of things in some cases (pages) . You need to echo out the ouput. Do you get any errors? Is there really a template called "category"? Does it have any unpublished and hidden pages using it? In addition, have you read these documentation? http://processwire.com/api/selectors/ http://processwire.com/api/variables/page/ http://processwire.com/api/variables/pages/ By the way, normally, you don't want to do something like $pages->find() without including a "limit"; It can find lots of things...and eat into your server resources, maybe hang your pages, hence, frustrate your web visitors, etc... Edit: corrected typos Edited July 1, 2013 by kongondo
Wanze Posted July 1, 2013 Posted July 1, 2013 $pages->find is supposed to return multiple pages. Use $pages->get to get only one page. So when using find, you need to iterate over your pages: $foundPages = $pages->find('template=category'); // Don't use $pages as variable name, it's reserved! foreach ($foundPages as $p) { echo "Found page with title" . $p->title; }
teppo Posted July 1, 2013 Posted July 1, 2013 @gtoirog: have you tried reading the docs, most importantly http://processwire.com/api/templates/ and http://processwire.com/api/variables/? This is all explained there
gtoirog Posted July 1, 2013 Author Posted July 1, 2013 Under the "Home" page, I have a few hidden pages, each with a template called "category". I just want to get the list of those pages filtering with "find("template=category")" and then loop through their children. I don't get anything by doing: $cpages = $pages->find("template=category"); foreach ($cpages as $cpage){ echo $cpage->title; } And I don't get any error.
kongondo Posted July 1, 2013 Posted July 1, 2013 You don't get anything because the pages are hidden. Add this to your selector include=hidden Please read this page: http://processwire.com/api/selectors/ and specifically this section in relation to access control in selectors. 1
gtoirog Posted July 1, 2013 Author Posted July 1, 2013 Thank you guys! Thanks, Kongondo. "include=hidden" works. Great community for newbies like me :-P Should do some more reading and use the cheatsheet more too. Processwire rocks!
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