Jump to content

Recommended Posts

Posted

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();
}

 

Posted

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?

  • Like 4

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
×
×
  • Create New...