cosmicsafari Posted May 24, 2017 Posted May 24, 2017 Hi All, I am working on a module at the moment which in theory will create a few simple fields, templates and pages which will all be linked together. All is going well so far, I have it generating said fields, templates and pages, however I would like to also set the pages sort order and icon programmatically at this stage also. I have yet to see any documentation or any other threads where this has been brought up, is it even possible programmatically without interacting with the database directly? This is the snippet which is generating my pages on the fly at the moment. foreach($arrayOfPages as $name => $page) { $p = new Page(); $p->template = 'page'; $p->name = $page['URL']; $p->title = $name; $p->parent = wire('pages')->get('name='.$page['parent']); //is it possible to set the icon and sort order at this point, before saving? $p->save(); }
Sergio Posted May 24, 2017 Posted May 24, 2017 A page does not have an icon, its template does, so if you are creating the template programmatically, use: $template->setIcon($icon); And about the sort order, do you wish to set the sort of the children or just append the page at the beginning of the list of its siblings? 4
cosmicsafari Posted May 24, 2017 Author Posted May 24, 2017 That would go some way as to why I couldn't find anything then I suppose lol I just want the page to appear at the bottom of the list under Pages > Home
Sergio Posted May 24, 2017 Posted May 24, 2017 Check these methods: $p->prepend($page) Prepend the given page to the beginning of the PageArray. $p->append($page) Append the given page to the end of the PageArray. More: https://processwire.com/api/arrays/page/ 2
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