Jump to content

Page Table Howto


Gideon So

Recommended Posts

Hi Kongondo,

Thanks for the reply and I read them all before I post this. I still don't get an idea on the pagetable field.

I tried it on my testing site.  Is it normal that everytime I add a table, a new page is added and the content in the child page shown on the pageTable feild. Is it the way it works??

If someone can write an tutorial or a example would be greate to us. Thanks.

Gideon

Link to comment
Share on other sites

  • 3 weeks later...

Hello,

PageTable is described as a leaner way to enter large amount of repeatable data into the admin backend, possibly with different sets of fields (think different templates).

The main advantages compared to the Repeater are:

1. PageTable can save new pages where you tell it to. Repeaters are saved deep down the Admin pages and are given cryptic names.

2. One PageTable field can make use of several different templates. Repeaters play according to the "One repeater = one template" rule (roughly put).

PageTable is a PageArray, so relevant methods are applicable. For example,  here is how to add and remove items from a PageTable field using the PW API:

// create a new page 
// IMPORTANT: your PageTable field must be configured to use template 'basic-page' in the field Setup tab

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

$page->of(false);

// add the newly created page to 'pt' which is a PageTable field

$page->pt->add($newpage);

$page->save();

Here is how to remove the first item from a PageTable field:

$page->of(false);

// 'pt' is a field of type PageTable
$page->pt->get(0)->delete();

$page->save();

That's a quick overview of this new field type. Give it a bit of your attention, it's quite promising.

Cheers,

Valery.

  • Like 8
Link to comment
Share on other sites

I tried it on my testing site.  Is it normal that everytime I add a table, a new page is added and the content in the child page shown on the pageTable feild. Is it the way it works??

Short answer to your question: Yes. That's the way how it works. ;)

Everything else is well explained in the Forum post, I think.

Link to comment
Share on other sites

I was going to start a new post but will piggyback on this one since my questions are related.

As Ryan has stated previously:

"PageTable lets you choose where [pages] should live, whether as children of the page being edited, or as children of some other parent page you designate."

Can someone elaborate on the pros and cons of storing pages as children of the page being edited vs. children of some other page?

I also understand that no matter the location of the child pages, additional child pages can only be added by using the PageTable field that has been set up. Are there some cases where it is better to hide stored pages under some other page to prevent confusion (from the client) when editing?

It would also be helpful to know what types of data are most appropriate for PageTables. For instance, instead of using a repeater field, would the use of PageTables be more appropriate for PDF files that need to include additional fields, such as description or category?

Link to comment
Share on other sites

@Lance -

I think you'll find that for the most part it is easiest to keep the pagetable pages as children of the page, but it will also depend a lot on your structure, and whether that page has children already, in which case put them somewhere else..

some examples of where i've use pagetables, and i think it will make sense:

| Page      | PageTable Children |
|-----------|--------------------|
| Album     | Tracks             |
| Slide     | Captions           |
| Portfolio | Images             |
| Vignettes | Vignette           |

i think if you use the reno theme and also lister pro, it actually won't matter that much where you put them; but in a lot of cases having them as children keeps things tidy and you can always get the relation of a pagetable item by calling it's parent.

and you can add pages not through the page table, and it will pick them up and ask you if you want to add them.

For PDFs, depending on the amount on one page, i might still consider good old repeaters

  • Like 2
Link to comment
Share on other sites

@Macrura

Thanks for your response. Your examples help me understand when to use PageTables.

You mentioned that "you can add pages not through the page table, and it will pick them up and ask you if you want to add them." What are you referring to here? 

Link to comment
Share on other sites

I just discovered that if you create child pages of a parent page, then decide to add a PageTable field that includes template of the existing child pages, those child pages won't be available to add to the PageTable field on the parent page.

In other words, if you are going to use a PageTable field, it appears that you'll need to make sure you create this field before you start adding child pages.

Link to comment
Share on other sites

yeah but a little api magic can cure that..

open up your tools or api playground and:

$pp = $pages->get(1234); // page you're adding the children to the page table

foreach($pp->children as $child) {
     $pp->page_table_field->add($child);
}
  • Like 8
Link to comment
Share on other sites

Hi @Valery,



I have also been looking for this "add an existing page" option for the PageTable. I have yet to find it, but after reading this thread, maybe it is only visible when you have the PageTable pages stored as children of the parent page. I am always storing my PageTable pages in a separate hidden folder.



Would be nice to have this as an alternative way to add or import pages into a PageTable.



Was also wondering if it would be possible to have one page in multiple PageTable fields (like a reusable common page).



Otherwise I am really liking this PageTable field and finding it very useful in all my recent client projects. It allows for some really interesting design and layout possibilities for mixed media and content heavy sites. 


Link to comment
Share on other sites

pretty sure that this only works for children of the page (showing new pages that can be added)... but will need to test it to confirm...

Was also wondering if it would be possible to have one page in multiple PageTable fields (like a reusable common page).

@Michael Murphy - this would basically be equivalent to my module in progress (currently an admin custom pages drop in), which would allow you to use regular page selects, but have the ability to access/edit them in a modal by clicking on the title..

you wouldn't be able to mix and match these with pagetables; i think of page table pages as pages that have to directly relate to to the page and can't be altered by any other page.

https://processwire.com/talk/topic/7588-admin-custom-files/?p=81866

there are other ways you could achieve various functionality - for example write a module that clones the pages in a page select to new page table pages where you could then have contextual access to those new pages without the risk of affecting some other place that page is being used;

  • Like 1
Link to comment
Share on other sites

Hello Michael,

In response to your earlier post: I've tried storing PageTable pages directly under the parent but it didn't work (for me, at least).

However, the idea behind trying to use existing pages in a PageTable field escapes me. Why not use Page fields with PageListSelect+ instead?

For instance, here is a screenshot of mock-up of a color chooser for a webshop item.

post-956-0-72056500-1417694097_thumb.png

  • Like 1
Link to comment
Share on other sites

  • 4 weeks later...

Hey man,

Sorry to bring this up again but based on the below quote by @Macrura I have tried hooking into the api with the below code to add some pages but it doesn't seem to work for me.

my PageTable field is called projects so have replaced page_table_field and used the correct parent ID and have tried calling this from say, the home page but it doesn't seem to work.

Any thoughts,

Cheers

yeah but a little api magic can cure that..

open up your tools or api playground and:

$pp = $pages->get(1234); // page you're adding the children to the page table

foreach($pp->children as $child) {
     $pp->page_table_field->add($child);
}
Link to comment
Share on other sites

Did you save the field? After adding the items?

$pp = $pages->get(1234); // page you're adding the children to the page table

foreach($pp->children as $child) {
   $pp->page_table_field->add($child);
}

$pp->of(false);
$pp->save('page_table_field');
  • Like 1
Link to comment
Share on other sites

I just tested that code and it is working fine here. Have you checked that the Add New button actually works for the page table field. Make sure there are no errors like template not allowed or anything else wrong with the page table config setup.

Do you have debug mode turned on?

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
  • Recently Browsing   0 members

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