FlorianA Posted January 8, 2018 Share Posted January 8, 2018 In order to hide some pages from my site menu, I've defined a field called 'menu_filter' with field type 'Selector'. In my page editor, I assigned a value to the field by choosing the combo boxes 'template' 'Equals' 'event'. After that I tried to apply this selector to a WireArray in a template file, but the selector string was 'template=45' rather than 'template=event', that means it shows the template's id, not its name. Therefore the selector doesn't work in my code. How can I fix this? Link to comment Share on other sites More sharing options...
Macrura Posted January 8, 2018 Share Posted January 8, 2018 what is your code? Link to comment Share on other sites More sharing options...
kongondo Posted January 9, 2018 Share Posted January 9, 2018 As we await your code... $t = $templates->get(45);// don't hardcode; get '45' value from the selector string if($t->name == 'event') { // stuff } // OR $t = $templates->get('event'); if($t->id == 45) { // stuff } Link to comment Share on other sites More sharing options...
FlorianA Posted January 9, 2018 Author Share Posted January 9, 2018 19 hours ago, Macrura said: what is your code? function getSettings() { return pages()->get('/site-settings/'); } $home = $pages->get('/'); foreach ($home->children()->not(getSettings()->menu_filter) as $childPage) { // the not() part has no effect } Link to comment Share on other sites More sharing options...
Robin S Posted January 9, 2018 Share Posted January 9, 2018 23 hours ago, FlorianA said: After that I tried to apply this selector to a WireArray The problem is here. The description of InputfieldSelector/FieldtypeSelector is "Build a page finding selector visually" (my emphasis). The inputfield returns a string that is suitable for using with the PW PageFinder - so you can use it with methods that query the database such as $pages->find($selector) or $page->children($selector) but it isn't guaranteed to work with in-memory selectors like $some_pagearray->find($selector), $some_pagearray->not($selector), etc. In your case a simple solution would be to use your Selector field to define the selector for pages that will appear in the menu (rather than what you don't want to appear in the menu). So you would set this in your Selector field... template > Not Equals > event ...and then use it in your template like this... function getSettings() { return pages()->get('/site-settings/'); } $home = $pages->get('/'); foreach ($home->children(getSettings()->menu_filter) as $childPage) { // ... } Link to comment Share on other sites More sharing options...
FlorianA Posted January 10, 2018 Author Share Posted January 10, 2018 This works. Thank you very much. Florian 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