Jump to content

Matrix/table built with children of two pages


Recommended Posts

I don't now if this is already possible to build with one of the available modules/fieldtypes. I so far tried Table, PageTable, Repeater and Multiplier but couldn't get them work exactly as I want.

I'm looking for a way to create a matrix/table that uses the children of two pages to build the row and column headers. In my case (an online shop), I want it to take the children of the page product variants and the children of the page currencies. In the end, it should render a matrix/table, where I can enter a fixed price for every variant in every currency.

Has anyone ever done something similar? Is there a fieldtype for this?

Link to comment
Share on other sites

Not sure what you want to archive with that but I think there is a better way to solve that. So could you add some more details?

I want to be able to set the price of a product (e.g. a T-Shirt) by its category (well, T-Shirts). Now for all products within the category T-Shirts, there are the same options (size S, M, L and color red, green, blue). So if I go to the category page of T-Shirts, I want a matrix that lists all the options of this product category and then let me set a price for each currency I'm offering the product in. I hope that's understandable :)

Link to comment
Share on other sites

Thanks for the tip, but I don't think that module can help me. It doesn't create the rows/columns based on the children of pages (so that I can add another child page and that the matrix would be extended automatically). If I would do it manually, I would prefer the fieldtype table.

Link to comment
Share on other sites

I want to be able to set the price of a product (e.g. a T-Shirt) by its category (well, T-Shirts). Now for all products within the category T-Shirts, there are the same options (size S, M, L and color red, green, blue). So if I go to the category page of T-Shirts, I want a matrix that lists all the options of this product category and then let me set a price for each currency I'm offering the product in. I hope that's understandable

I am still not 100% clear, but it sounds to me like maybe you don't want a new way of storing product/price info, but just a new way of entering it. It sounds like you still want the data stored in the product's page fields. Is that correct?

If so, you might be looking at implementing something custom with AdminDataTable (core module often used by other modules), or HandsOnTable. Here are a couple of links for inspiration:



and of course the ProTable field type. 

I think with ideas from those you could build a process module that builds an editable table using the product/price info from the fields from product pages. When saving the table, the data would be written back to the appropriate pages.

Am I on track at all?

  • Like 1
Link to comment
Share on other sites

It might help if I add a screenshot of what it looks like if it's manually built with the fieldtype table. The downside is that I have to create all possible variations by hand, and that if I add a new currency or a new product option, it's not populated automatically to this table.

One solution (at least for the product options size and color) to this would be if the fieldtype table would allow columns to be of the type page and then output them as radios/checkboxes.

It would be even cooler of course if the variants (all possible combinations of the product options size and color) would also be built automatically ;)


Link to comment
Share on other sites

It sounds like you still want the data stored in the product's page fields. Is that correct?

No, the product itself (T-Shirt) is assigned to a category (T-Shirts), and all the pricing information is stored within the category page.

  • Like 1
Link to comment
Share on other sites

It really sounds like you want ProFields, the table plugin is extremely flexible. Are you wanting to make changes to all of you separate pages via one template, or are you still wanting to edit all of the pages directly?

As I mentioned at the beginning, I already tried to use the ProFields Table, Multiplier and Page Table. The screenshot in my post above is actually from the ProFields Table fieldtype.

It should be one template in the end that I can use on different pages (-> product categories).

Link to comment
Share on other sites

Are you basically creating a main page and the variants are children of that page?

So, they all have the same prices, for instance, but other variations are possible with the children?

If so, you could do something like this:

Parent - T-Shirts

Field: Default price (USD)

Child page - 

T-shirt crazy style

Field: override price (USD) - normally left blank.

In your template for the child, you can call the price from the parent page (see the API for parents), checking whether the override price as been set. If it hasn't you display from the parent, if it has been set, you display from the child.

You can do this will any field - set defaults in the parent, but allow for overrides for the children.

  • Like 1
Link to comment
Share on other sites

I'm not sure if I can follow your example. Let me add another screenshot to clarify my setup. I have a product page (T-Shirt) that is displayed on the frontend. Then, there's the Tools page (only for backend), where I define a products attributes and categories.

Now, within the page T-Shirts (which represents a product category) I want to be able to have the table I mentioned above where I can set the prices for each product variant of the attributes size and color – pretty much as in my other screenshot above.

The product page T-Shirt then actually just has a drop-down to select a product category (in this case T-Shirts).


Link to comment
Share on other sites

Okay, I am probably going to get this wrong, but let me think this through.

You want a list of attributes, but without prices - you add the price later in the T-Shirt page?

So, for instance, you could have a repeater (possibly better with a page table) that has two fields:

Page Field, picking up a list of attributes and a text field for the price.

You add a line, choose the attribute type from the page field drop down (must be single select, of course) and you put in your price.

You can then loop through the repeater to list out all the attributes and associated prices for that product..

When it comes to a category, if you are creating the product page under its parent, then it already has a category - its parent! :)

Oh, I should add, that the attributes can have more than just a title - they can have images, extra info, anything you like as they are pages in their own right - but you only use the title field when selecting them.

  • Like 2
Link to comment
Share on other sites

I think we got tangled up in my use case. Maybe I have to go back to the beginning, because what I'm looking for has different use cases in my opinion.

What I'm looking for is to have some kind of matrix fieldtype where I can define the row and column headers. Now, these headers should automatically be built by the page title of definable pages (actually their respective child pages).

Say I have two pages (Size and Color) with the following child pages:


   – S

   – M

   – L



   – Red

   – Blue

   – Green

Now in this matrix fieldtype, I could apply Size to be the row header and Color the column header. This would result in a matrix like this:

   | Red | Blue | Green |


S  |     |      |       |


M  |     |      |       |


L  |     |      |       |


Now, if I add another child to the page Color (e.g. Black), the matrix would be automatically extended: 

   | Red | Blue | Green | Black |


S  |     |      |       |       |


M  |     |      |       |       |


L  |     |      |       |       |


Is there already a fieldtype like that?

Link to comment
Share on other sites

OK, let me wade in as well :-)


I don't think there is a module like that. Does this have to be a fieldtype or would a ProcessModule do? i.e. a custom view/page within the admin. The table cells would be input fields that contain any data you want. This is a similar idea to what Adrian mentioned above. The ProcessModule would just be a means of easily entering your data but these would be stored within the fields of your pages themselves. The advantage with this approach is that you could have a table of all your products, then clicking on an edit button/link would bring up the matrix. This would be built on the fly based on the number of your 'child pages'...Anyway, just thinking out loud here...

  • Like 1
Link to comment
Share on other sites


Creating the matrix is the easy part. The problem is deciding where and how that data will be stored. At the end of the day you want to be able (preferably) to easily query your data using PW API, say find the price of 'small red' t shirts.... The problems with my solution are, e.g. where do you store the price of a 'Large Blue' t-shirt? If you had a fixed number of variations, fine, but in your case they are dynamic. A 'pink' variant can be added later and you want to be able to accommodate that...hmm...

Maybe the fieldtype route is the way to go :-). I am not sure how Martijn's FieldtypeJson works but it seems to be able to accommodate any number of columns. If you want to go down that route, then you can adjust that Fieldtype to suit your use case. It's a matter of rewriting the code and renaming the module class. Of course, you need to know what you are doing... :-). There's also Ryan's event fieldtype that could be modified to do what you are after...

Link to comment
Share on other sites

Me again... :-)

Will your product sizes be fixed, i.e, always S, M, L? If yes, can your matrix be like this instead?

           |  S  |  M   |  L   |
Red   |      |        |       |
Blue    |     |        |       |
Green  |     |       |       |
Black   |     |       |       |
meaning....only add rows with new variants but columns will be fixed...
  • Like 1
Link to comment
Share on other sites


I like the thinking but you never know when an extra X will get added to a size; particularly medium. In other words, I suspect the table would need to accept changes in either dimension.

How about simply concatenating the x and y variable to give a key that can then have a simple value stored against it? So you'd end up with a table that had an indexed product page id, an indexed "key" and an "amount" column. The function to make the key would just do something like...

function makeKey($size, $variation)
    $size      = wire()->sanitizer->name($size);
    $variation = wire()->sanitizer->name($variation);

    $key = "$size/$variation";

    return $key;
  • Like 2
Link to comment
Share on other sites


Good point. I was thinking along those lines (the indexed key) but wasn't sure how search would work (i.e. grab 'red small' t-shirts) using PW API and related performance issues. Back then, I was thinking storing the pairs using json like syntax $size:$variation - something similar to yours. 

Link to comment
Share on other sites


Just to answer my own question about how the search for the 'indexed key' would work [database side of things] - this could either work  the way PW handles repeater fields - data stored as comma separated integers (1234, 5688), i.e. $size,$variation ID pages respectively as you suggested, or why not store them as PW multiple page fields - i.e. a row for each addition, consisting of page id (integers) i.e. 

E.g. assuming Red = ID 1124, small = 2545 and medium = 2745

$variation    $size   $amount

1124           2545    $20

1124           2745   $10

On the inputfield side of things, the user will still be able to see a table similar to the one I posted above that would grow both vertically and horizontally with each new addition of size and variation...Of course horizontal growth could get very messy very quickly... :-)

Edited by kongondo
  • Like 2
Link to comment
Share on other sites

Hi Charger,

I thought you'd given up on this given your absence :P   :-)

I'd started to work on something (it was actually working, i.e. dynamically adding rows and columns - except for saving to the DB) but then I hit a few snags and was wondering whether this wouldn't be best achieved by a dedicated ProcessModule or an extended PageTable....If you are about later, I could try and explain...

ps: low-level or high-level?? :unsure: 

  • 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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By kixe
      Field that stores one or more references to ProcessWire pages with additional data in field context.
      Values are editable via page edit modal of the referenced page provided from the field if module AdminPageFieldEditLinks is installed and "Enable link to create new pages?" is checked in field settings.
      Requirements: AdminPageFieldEditLinks >= 3.1.4
      Use case example:
      The planning of the Tonmeistertagung in the CCD (Congress Center Düsseldorf) from November 3rd, 2021 to November 6th, 2021 is in the finalization phase.
      The conference consists of a conference part and an exhibition. The planning is done via a separate frontendless PW instance. There, all companies (pages) that are active at various events are kept in a pool. Changes (address, logo) can always be done there. For the exhibition of the current conference in November, the exhibitor-companies (pages) are selected via a page reference field. A stand number must now be assigned to each selected company (page). We had originally solved this using the Profield FieldtypeTable. However, this had the disadvantage that each entry again made all companies available for selection and did not recognize which were already selected in a previous table row. The new field type now allows the value (company's stand number) to be assigned to a Company (page) in context to a specific Pagefield living in a specific page.
    • By Robin S
      This module lets you add some custom menu items to the main admin menu, and you can set the dropdown links dynamically in a hook if needed.
      Sidenote: the module config uses some repeatable/sortable rows for the child link settings, similar to the ProFields Table interface. The data gets saved as JSON in a hidden textarea field. Might be interesting to other module developers?
      Custom Admin Menus
      Adds up to three custom menu items with optional dropdowns to the main admin menu.
      The menu items can link to admin pages, front-end pages, or pages on external websites.
      The links can be set to open in a new browser tab, and child links in the dropdown can be given an icon.
      Requires ProcessWire v3.0.178 or newer.
      Example of menu items

      Module config for the menus

      Link list shown when parent menu item is not given a URL

      Setting child menu items dynamically
      If needed you can set the child menu items dynamically using a hook.
      $wire->addHookAfter('CustomAdminMenus::getMenuChildren', function(HookEvent $event) { // The menu number is the first argument $menu_number = $event->arguments(0); if($menu_number === 1) { $colours = $event->wire()->pages->findRaw('template=colour', ['title', 'url', 'page_icon']); $children = []; foreach($colours as $colour) { // Each child item should be an array with the following keys $children[] = [ 'icon' => $colour['page_icon'], 'label' => $colour['title'], 'url' => $colour['url'], 'newtab' => false, ]; } $event->return = $children; } }); Create multiple levels of flyout menus
      It's also possible to create multiple levels of flyout submenus using a hook.

      For each level a submenu can be defined in a "children" item. Example:
      $wire->addHookAfter('CustomAdminMenus::getMenuChildren', function(HookEvent $event) { // The menu number is the first argument $menu_number = $event->arguments(0); if($menu_number === 1) { $children = [ [ 'icon' => 'adjust', 'label' => 'One', 'url' => '/one/', 'newtab' => false, ], [ 'icon' => 'anchor', 'label' => 'Two', 'url' => '/two/', 'newtab' => false, 'children' => [ [ 'icon' => 'child', 'label' => 'Red', 'url' => '/red/', 'newtab' => false, ], [ 'icon' => 'bullhorn', 'label' => 'Green', 'url' => '/green/', 'newtab' => false, 'children' => [ [ 'icon' => 'wifi', 'label' => 'Small', 'url' => '/small/', 'newtab' => true, ], [ 'icon' => 'codepen', 'label' => 'Medium', 'url' => '/medium/', 'newtab' => false, ], [ 'icon' => 'cogs', 'label' => 'Large', 'url' => '/large/', 'newtab' => false, ], ] ], [ 'icon' => 'futbol-o', 'label' => 'Blue', 'url' => '/blue/', 'newtab' => true, ], ] ], [ 'icon' => 'hand-o-left', 'label' => 'Three', 'url' => '/three/', 'newtab' => false, ], ]; $event->return = $children; } }); Showing/hiding menus according to user role
      You can determine which menu items can be seen by a role by checking the user's role in the hook.
      For example, if a user has or lacks a role you could include different child menu items in the hook return value. Or if you want to conditionally hide a custom menu altogether you can set the return value to false. Example:
      $wire->addHookAfter('CustomAdminMenus::getMenuChildren', function(HookEvent $event) { // The menu number is the first argument $menu_number = $event->arguments(0); $user = $event->wire()->user; // For custom menu number 1... if($menu_number === 1) { // ...if user does not have some particular role... if(!$user->hasRole('foo')) { // ...do not show the menu $event->return = false; } } });  
    • By tcnet
      This module for ProcessWire sends a notification email for each failed login attempt. Similar modules exists already in the module directory of ProcessWire. However, this module is designed to notify, even if specified user doesn't exist.
      The settings for this module are located in the menu Modules=>Configure=>LoginFailNotifier.
      Notification email
      Specifies the email address to which the notification emails should be sent.
        Email subject
      Specifies the subject line for the notification email.
        Post variables
      Specifies the $_POST variables to be included in the notification email. Each variable must be separated by a comma. For example: login_name,login_pass
        Server variables
      Specifies the $_SERVER variables to be included in the notification email. Each variable must be separated by a comma. For example: REMOTE_ADDR,HTTP_USER_AGENT
      Link to ProcessWire module directory:
      Link to github.com:
    • By Fokke
      ProcessWire 3.x markup module for rendering meta tags in HTML document head section. Note that this module is not a full-blown SEO solution, but rather a simple tool for rendering meta tags based on module configuration. Adding custom meta tags is also supported.
      Built-in meta tags
      The following meta tags are supported out-of-the-box:
      Document title consisting of page title and site name Character set Canonical Viewport Description Keywords Hreflang tags Open Graph og:title og:site_name og:type og:url og:description og:image og:image:width og:image:height Twitter meta tags twitter:card twitter:site twitter:creator twitter:title twitter:description twitter:image Facebook meta tags fb:app_id The full documentation with configurable options can be found here: https://github.com/Fokke-/MarkupMetadata
      ProcessWire>=3.0.0 PHP >=7.1 Installation using Composer
      composer require fokke/markup-metadata Manual installation
      Download latest version from https://github.com/Fokke-/MarkupMetadata/archive/master.zip Extract module files to site/modules/MarkupMetadata directory.
    • By m.sieber
      ITRK-Service for ProcessWire
      Module for the automated transfer of imprint, data protection declaration and terms and conditions from IT-Recht Kanzlei to your ProcessWire installation
      What is ITRK Service for ProcessWire?
      ITRK-Service for ProcessWire is a free module for ProcessWire CMS. It provides an interface to the update service of IT-Recht Kanzlei, via which the legal texts of your online presence are automatically updated. In this way, the texts remain legally secure and warning-proof in the long term. Imprint, data protection declaration, revocation and general terms and conditions are currently supported.
      You can find our documentation (in german language) here: https://www.pupit.de/itrk-service-for-processwire/dokumentation/

      Download: https://www.pupit.de/itrk-service-for-processwire/
      Github: https://github.com/pupit-de/pwItrkServiceConnector
  • Create New...