vknt Posted October 9, 2011 Share Posted October 9, 2011 Hi, in 2.1 we can provide a custom selection code for the selectionlist of the Page Field. This works: return $pages->find("template=page_languagecontainer"); this doesn't anymore: return $pages->find("template=page_languagecontainer")->children(); I get this error TemplateFile: Method PageArray::children does not exist or is not callable in this context Am I missing something here? I've tried many things but it seems toalways give an error when I try to call children at the end of the query.. Thx in advance guys! Link to comment Share on other sites More sharing options...
Soma Posted October 10, 2011 Share Posted October 10, 2011 it should be return $pages->get("/")->find("...")->children("..."); Link to comment Share on other sites More sharing options...
apeisa Posted October 10, 2011 Share Posted October 10, 2011 Actually that wouldn't work either. Children() is method for page object (http://processwire.com/api/variables/page/), but find() returns multiple pages (pageArray: http://processwire.com/api/arrays/page/). Ie. this should work: return $pages->find("template=page_languagecontainer")->first()->children(); Link to comment Share on other sites More sharing options...
Soma Posted October 10, 2011 Share Posted October 10, 2011 Apeisa, actually it works, I tested it before posting. But I think I messed up, you're right. But using get("/")->children() instead would work. EDIT: I'm confused, apeisa method doesn't work, just tested. Returns "Call to a member function children() on a non-object" even when using ->first(). I'll let Ryan answer here. Link to comment Share on other sites More sharing options...
vknt Posted October 10, 2011 Author Share Posted October 10, 2011 Apeisa's code works for me. However it's not what I want, but I now understand why. thx apeisa I want to have all the children of the pages with template page_languagecontainer. Now I only have the children of 1 of them. Is there a way to do this? Thx in advance. Link to comment Share on other sites More sharing options...
Soma Posted October 10, 2011 Share Posted October 10, 2011 Even more confused. But now I know, I did something wrong, I did a find for hidden pages, and forgot to include=all... Your're right it does work, but with the limitations you mention. I'm not sure, how flexible it should be but you could do something like this: $p = $pages->get("/sidebar-elements/")->children(); foreach($pages->get("/polls/")->children() as $c) $p->append($c); return $p; Link to comment Share on other sites More sharing options...
apeisa Posted October 10, 2011 Share Posted October 10, 2011 I want to have all the children of the pages with template page_languagecontainer. Now I only have the children of 1 of them. Is there a way to do this? Many ways to achieve this, but I would use something like this: $pa = new PageArray(); foreach ($pages->find("template=page_languagecontainer") as $p) { $pa->import($p->children()); } Link to comment Share on other sites More sharing options...
vknt Posted October 10, 2011 Author Share Posted October 10, 2011 That worked Thanks apeisa, learned something new today! Link to comment Share on other sites More sharing options...
apeisa Posted October 10, 2011 Share Posted October 10, 2011 That worked Thanks apeisa, learned something new today! Great! Glad you got it working. Link to comment Share on other sites More sharing options...
ryan Posted October 10, 2011 Share Posted October 10, 2011 Unless you know the templates (or parents) used by the children, I think Antti's suggested method is best. 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