Jump to content

Page Table Howto


Recommended Posts

Great - thank you very much!

The query and if statements are never a real problem since i like to try out how it works and dig into - but sometimes i don't find the right hook or methode that i have to jump on (ProcessPageSearch::executeFor).

Thank you for the hint - i will provide a complete snippet if it works.

(Just some little offtopic - i place this kind of hooks until now in my admin.php - i don't get the whole difference between ready.php and admin.php...it's not really documentated where i should run/setup different little hooks/tasks better)

  • Like 1
Link to post
Share on other sites

Ok i tried some different setting, but without luck for the function - but i studied the ProcessPageSearch and found:

// non superuser doesn't get any admin pages in their results
$s .= ", has_parent!=$adminRootPage"; 

And now come one of PW greatest things - without fear i switched the parent (for the contentblock root) from my settings page to admin page...with kinda a 300 pages there....switched parent -> all works, editors don't get any single PageTable Pages -> all good!

Best regards mr-fan

  • Like 2
Link to post
Share on other sites

Glad you found a solution by placing under admin, but if you want, here is a tested option. Place this in your admin.php - just replace the xxxx with the id of the Settings page. With this the autocomplete won't return any pages under Settings.

$this->pages->addHookAfter('ProcessPageSearch::executeFor', null, 'removeBranchFromSearch');

function removeBranchFromSearch($event) {
    $response = $event->return;
    $responseArray = json_decode($response, true);
    $matches = $responseArray['matches'];
    $i=0;
    foreach($matches as $match) {
        if(wire('pages')->get($match['id'])->is("has_parent=xxxx")) {
            unset($matches[$i]);
        }
        $i++;
    }
    $responseArray['matches'] = $matches;
    $event->return = json_encode($responseArray);
}
  • Like 2
Link to post
Share on other sites
  • 2 months later...

The profields pagetable has been around in core for some time.

I just started playing around it.

What is the purpose of a pagetable with more than one template ?

In my testing, with a pagetable configured for more than one template, as show below

post-2272-0-09626900-1461111717_thumb.pn

Two add buttons will show on the pagetable field.

Could you guys give me an example or scenario to describe when to use multiple templates?

Link to post
Share on other sites

It gives your site editors the ability to add different content types "blocks" in whatever order they wish. For example, a block of text, then an image, or a video, or a two column block of text, perhaps a map - whatever you set up for them. The great thing about this, compared to letting them embed images etc within a CKEditor textarea is that you can control the output of these, rather then letting them potentially mess things up ;)

Link to post
Share on other sites

To stay with your example of products. You might have two different groups of products: digital ones and physical ones. A shopping cart might have a pagetable holding both types of product and displays the price, which is part of both groups. But the physical products might have addtional fields like how much products are in stock, which isn't applicable for digital products, hence the different templates.

Link to post
Share on other sites

A bit of history:

PageTable is part of the ProFields. Thanks to Avoine (the sponsors) it has been made available as a free ProField. Here's a link to more info about the different ProFields, thanks to a question by @cstevensjr :-)

  • Like 3
Link to post
Share on other sites

instead of using below code to create a page table row

$newpage = $pages->add('basic-page', '/about/', 'address', array('title' => 'Write to us'));

could i use the traditional way of creating a new page ?

ie.

$pt_parent = $pages->get('/page-table-parent');
$p = new Page();
$p->template = "page-table-template";
$p->parent = $pt_parent;
$p->title = "page table title";
$p->body = "page table body";

$page->of(false);
$page->page_table_field->add($p);
Link to post
Share on other sites
  • 1 year later...

Copy / Clone single pagetable-pages to another page

Hi is it possible to clone / copy a pagetable-page to another "parent"-page with the same pagetable field via the backend? 

 

Many Greets, Jens.

Link to post
Share on other sites
  • 4 months later...

Hello @ all,

I am trying to find a solution to change the table headers via a hook. These are the hooks that can be use with a pagetable field:

screenshot-processwire.com-2017-11-13-11-14-33.png.bfe26735f5bcd28c879151df6f4b22c1.png

The fields of the pagetable can be entered in the configuration of the pagetable field inside a textarea:

screenshot-www.juergen-kern.at-2017-11-13-11-13-57.png.b4e892a1532959b4a294fd98bbff3463.png

I guess there should be a possibility to change the labels of these fields which are used inside the table header. Changing it directly at the fields is not an option in this case.  My idea was to hook like this:

addHookBefore('InputfieldPageTable::render', function($event)

But I have no idea at the moment how to get the labels of the fields. Does anyone has a hint how it could be done?

Link to post
Share on other sites

Thanks @adrian,

unfortunately my solution does not work if the page table is updated via Ajax after a child page is saved in the modal. I have tried to use the code inside init.php instead of ready.php but I cannot solve this problem. Do you have an idea?

Link to post
Share on other sites
  • 4 months later...
On 3/12/2015 at 2:40 AM, adrian said:

Here is something I hacked together quickly for automatically adding new child pages to the pagetable field. This is only if you are using the page as the parent. It also handles deletion of items if they are trashed externally. I also disabled the internal check for orphans - because they have been automatically added already, there is no need for the "Children were found that may be added to this table. Check the box next to any you would like to add." option.

I seems to be working great here, but please test carefully!!

Add this to your admin.php file:


wire()->addHookBefore('InputfieldPageTable::render', function($event) {
    $pp = wire('pages')->get(wire('input')->get->id);
    $ptf = $event->object;

    //remove pages from pagetable field if they were externally trashed
    foreach($pp->{$ptf->name} as $item) {
        if($item->is(Page::statusTrash)) $pp->{$ptf->name}->remove($item);
    }

    //add pages to pagetable field if they were created externally
    foreach($pp->children as $child) {
        if(!$ptf->has($child->id)) {
            $pp->{$ptf->name}->add($child);
            $pp->of(false);
            $pp->save($ptf->name);
        }
    }

    //reset orphans property so that we don't get a message asking to add new pages that are now already automatically added
    $ptf->setOrphans(new pageArray());
});

Instead of adding this to admin.php, I've added it to init.php. It's ok right?

  • Like 1
Link to post
Share on other sites
15 hours ago, PWaddict said:

Instead of adding this to admin.php, I've added it to init.php. It's ok right?

Yeah - I don't think init.php and ready.php existed when I wrote this. I guess the only advantage to admin.php is that it is only called in the backend, whereas init.php and ready.php are called in frontend as well. It won't make any significant impact on performance though, so whatever works for you.

  • Like 2
Link to post
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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...