Jump to content

Open page tree (ProcessPageList) branches by code


Karl_T
 Share

Recommended Posts

I want to make some branches of a page list(tree) open onload. I am using Admin Custom Page module with the following code.

<?php
$p = $this->modules->get('ProcessPageList');
$p->set('id',1037);
return $p->execute();

I changed the parent successfully from home to the wanted page, but the tree closed every time after reload.

I added the following code before return $p->execute():

$this->wire('config')->js('ProcessPageList', array(
	'openPageIDs' => array(1045,1046), 
));

The javascript shows error. Then I tried this:

$this->wire('config')->js('ProcessPageList', array(
	'openPageIDs' => 1045, 
));

The branch of the ID open with delay. I want to open multiple branches at the same time. Thanks.

Link to comment
Share on other sites

If you set an array to openPageIDs then it must be an array of page IDs as strings. For example:

$this->wire('config')->js('ProcessPageList', array(
    'openPageIDs' => array('1045','1046'), 
));

If you would like the convenience of passing multiple page IDs as a GET parameter you could do this in /site/ready.php:

$this->addHookBefore('ProcessPageList::execute', function($event) {
    $branches = $this->sanitizer->intArray(json_decode($this->input->get->branches));
    if(count($branches)) {
        $this->wire('config')->js('ProcessPageList', array(
            'openPageIDs' => array_map('strval', $branches)
        ));
    }
});

Then you would link to the page tree like this:

/processwire/page/?branches=[1045,1046]

 

  • Like 3
Link to comment
Share on other sites

1 hour ago, Robin S said:

If you set an array to openPageIDs then it must be an array of page IDs as strings. For example:


$this->wire('config')->js('ProcessPageList', array(
    'openPageIDs' => array('1045','1046'), 
));

Thanks! This just works, although this has a 0.5 second delay due to separate ajax call.

  • Like 1
Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...