Jump to content

Custom Code for selectable pages not working properly


vknt
 Share

Recommended Posts

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

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. :D

Link to comment
Share on other sites

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

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...