Robin S Posted August 8, 2015 Share Posted August 8, 2015 I want to create a PageArray containing a number of pages that I will select by name (to use with the MarkupSimpleNavigation module). I'm using the code below and it works fine... $items = new PageArray(); $items->add( $pages->get("/page-1/") ); $items->add( $pages->get("/page-2/") ); $items->add( $pages->get("/page-3/") ); $items->add( $pages->get("/page-4/") ); $items->add( $pages->get("/page-5/") ); ...but it seems a bit long-winded. Is there a way to add multiple pages to my PageArray in a single line? I'm not looking to create a PageArray via selector; I want to manually add pages by name. Link to comment Share on other sites More sharing options...
horst Posted August 8, 2015 Share Posted August 8, 2015 (edited) $a->import($items); . or one of the other methods that are available with pagearrays / wirearrays. Edited August 8, 2015 by horst 1 Link to comment Share on other sites More sharing options...
sforsman Posted August 8, 2015 Share Posted August 8, 2015 I know you said you didn't want to use a selector, but I'm just wondering why on earth? You are effectively doing the same as $items = $pages->find('name=page-1|page-2|page-3|page-4|page-5, parent=/'); But your code will just execute slower. 4 Link to comment Share on other sites More sharing options...
Robin S Posted August 8, 2015 Author Share Posted August 8, 2015 @sforsman Thanks - your suggestion is just what I need. I thought I wouldn't be able to use a selector because the pages I want to select don't share any common attribute (parent, template, etc). It didn't occur to me that I could just find a list of names. @horst Thanks for the reply - sforsman's suggestion is probably the solution I need but I'm interested to understand how the import method could be used. The import method accepts a PHP array or a WireArray - I take it you're suggesting a normal PHP array rather than a WireArray seeing as my question is how to get items into a PageArray (WireArray) in the first place. I tried the import method and it worked with an array of page IDs... $ids = array(1041, 1042, 1043, 1044, 1045); $items = new PageArray(); $items->import($ids); ...but it didn't work with an array of page names... $names = array("/page-1/", "/page-2/", "/page-3/", "/page-4/", "/page-5/"); $items = new PageArray(); $items->import($names); Is there a way to use import with page names? Link to comment Share on other sites More sharing options...
LostKobrakai Posted August 9, 2015 Share Posted August 9, 2015 The import methods does not search for pages. It does import either WireArrays of WireData objects (like Pages) or a simple php array of WireData objects. So it's not so important how those objects are group but the objects must be of the right type when importing. 1 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