Jump to content

Page Inputfield Selector


Timo
 Share

Recommended Posts

Hi, 

I'm looking for help with my page field selector. I want a field which allows me to select internal pages to link to.

I have a strict naming, where all relevant page templates for this case begin with "page-" . So I would love to do something like this:

template^=page-

but the system tells me this is not allowed. Same for template%=, template*= etc.

Edit: I solved it now with a custom php snippet. This works, but maybe there is a more elegant solution?

$tmp = new PageArray();
$all = $pages->find('id|has_parent=1');
foreach(  $all as $p ) {
  if( strpos($p->template->name, 'page-') === 0 ) {
    $tmp->push( $p );
  }
}

return $tmp;
Link to comment
Share on other sites

Thanks for your answer, looks clever, but you cannot use $templates in the "Custom PHP code to find selectable pages".

template.name^= doesn't work, either.

I got my solution now, but I think this is more complicated than it should be.

Link to comment
Share on other sites

Okay, I guess that's too advanced for my basic processwire and php knowledge. Probably I don't get what you are trying to tell me. This doesn't work either:

$tpls = $this->templates->find("name^=page-");
$items = $pages->find("template=$tpls");

Thanks anyway, I resign and stay with my foreach-loop.

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

×
×
  • Create New...