adrianmak Posted December 21, 2015 Share Posted December 21, 2015 I knew that page reference field can be user for categorization. Is it possible to select a child root as page reference. Take an example. I created a page named Categories, the page structure look like below Home (site root) +--About Company +--Our Services +--Product +--Contact Us +--Categories +--News +--Company news +--Market news +--Products type +--plastic +--metal +--Pictures type +--plastic +--metal +--paper +--company The child pages , News, Products type, Pictures type, under categories are no association to each others. For a Product page with a page reference field, only "Products type" has meaning to Product. Could I select "Products type" child root as page reference ? Link to comment Share on other sites More sharing options...
SiNNuT Posted December 21, 2015 Share Posted December 21, 2015 Yes, if you have a page reference field that is specific to Product pages, you can go to the field settings, under the Input tab and then select Products type as Parent of selectable pages. Or use one of the other settings. If your page reference field is used on different kinds of pages (Product, News etc.) and you want a 'dynamic' Parent of selectable pages, depending on the type of page it is used on, maybe this can be done via the custom php option. Some sort of conditional parent, but i'm not sure if possible. Link to comment Share on other sites More sharing options...
adrianmak Posted December 21, 2015 Author Share Posted December 21, 2015 How or is it possible to select multiple child root as page reference ? instead of using two separate page reference fields Something look like..... Link to comment Share on other sites More sharing options...
SiNNuT Posted December 22, 2015 Share Posted December 22, 2015 I'm not sure. This would involve an inputfield that allows for <optgroup>. I've read that this should be possible somehow with InputfieldSelect but i've yet to read how exactly this could be done. More info here: https://processwire.com/talk/topic/11348-select-input-field-with-opt-groups/ 1 Link to comment Share on other sites More sharing options...
LostKobrakai Posted December 22, 2015 Share Posted December 22, 2015 It's possible to have the inputfield render optgroups but FieldtypePage has no option to provide the necessary nesting of pages to support that. I think currently only manual setup does allow for those groupings. Link to comment Share on other sites More sharing options...
adrianmak Posted January 10, 2016 Author Share Posted January 10, 2016 one more question regarding page reference. From op, I grouped categories into three groups , News, Products type and Pictures type In which each group is referenced by three template independently ie News is referenced by News template Product type is referenced by Product template Pictures type is referenced by Picture template How could I create a single page field type and dynamic associated each group for each page template. Instead of create three different category input fields Link to comment Share on other sites More sharing options...
LostKobrakai Posted January 10, 2016 Share Posted January 10, 2016 I think the only solution would be hook into InputfieldPage::render and replacing all it's logic with a custom implementation for the field you need the optgroups for. Link to comment Share on other sites More sharing options...
Jan Romero Posted January 10, 2016 Share Posted January 10, 2016 News is referenced by News template Product type is referenced by Product template Pictures type is referenced by Picture template How could I create a single page field type and dynamic associated each group for each page template. Instead of create three different category input fields In your page field settings go to Input, expand “Custom PHP code to find selectable pages” under “Selectable Pages”. You can fill your input field according to the template of the page being edited, by checking $page->template: if ($page->template->name === 'News') { return $pages->find('parent=/categories/news/'); } else if ($page->template->name === 'Product') { return $pages->find('parent=/categories/products-type/'); } else if ($page->template->name === 'Picture') { return $pages->find('parent=/categories/pictures-type/'); } Make sure to remove all the other options from “Selectable Pages”. Sometimes they don’t get overridden properly. 1 Link to comment Share on other sites More sharing options...
adrianmak Posted January 10, 2016 Author Share Posted January 10, 2016 In your page field settings go to Input, expand “Custom PHP code to find selectable pages” under “Selectable Pages”. You can fill your input field according to the template of the page being edited, by checking $page->template: if ($page->template->name === 'News') { return $pages->find('parent=/categories/news/'); } else if ($page->template->name === 'Product') { return $pages->find('parent=/categories/products-type/'); } else if ($page->template->name === 'Picture') { return $pages->find('parent=/categories/pictures-type/'); } Make sure to remove all the other options from “Selectable Pages”. Sometimes they don’t get overridden properly. Thank you very much. Link to comment Share on other sites More sharing options...
adrianmak Posted January 12, 2016 Author Share Posted January 12, 2016 Last night, I implemented the custom php code to find selectable pages. Pages structure Here is my code The categories of pages under "News" pages could get the right categories from "Categories" correctly. However, PW returned an error with a selected category of this page. "Error saving field "categories" - Page 1046 is not valid for categories (Page 1046 does not have required parent 1) PS it's working for the "Recycling Library" Link to comment Share on other sites More sharing options...
LostKobrakai Posted January 12, 2016 Share Posted January 12, 2016 Remove the parent "Home". 2 Link to comment Share on other sites More sharing options...
adrianmak Posted January 12, 2016 Author Share Posted January 12, 2016 Remove the parent "Home". I see~~~~~~ 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