Search by

nr / pagetablenext

nr

PageTable with scoped admin preview

Package info

github.com/neuerituale/PageTableNext

Type:pw-module

pkg:composer/nr/pagetablenext

Statistics

Installs: 182

Dependents: 0

Suggesters: 0

Stars: 5

Open Issues: 0

2.1.0 2026-11-29 19:18 UTC

This package is auto-updated.

Last update: 2026-11-29 20:53:00 UTC


README

What it does

This module is a solid base for the implementation of custom builder systems and modular template systems. It provides a list of PageTable based content elements and adds an intuitive UI to the ProcessWire backend to make content creation and editing as simple and fun as possible. It offers functions to create, publish, move, delete, hide, copy and paste content elements.

The rendering logic of the module is detached from the ProcessWire backend scope via Shadow DOM and allows for custom rendering and styling of the elements in the backend, so the backend preview can look identical to the front end, or anything like you can imagine. It ships with some helper functions that simplify the handling of content elements.

The module extends Ryan's PageTable and is strongly inspired by PageTableExtended by mademyday. Big thanks to both of them.

Features

  • Custom rendering (e.g. frontend preview) in the backend. Content elements are encapsulated in Shadow DOM.
  • Instant publishing and unpublishing.
  • Copy and paste with check of allowed templates (page-wide).
  • Editing in the ProcessWire modal.
  • Instant deletion of content elements.
  • Custom JavaScript actions can be easily added.
  • Page references support.
  • Triggers save on all referenced pages (e.g. clear cache).
  • Shows the "view" link in the edit view that leads to the referenced page /link/to/parent/#s[PageId].
  • Manipulates the breadcrumb navigation of the content element (Shows the first referenced page).
  • Support for ProcessGraphQL with the additional modules GraphQLFieldtypePageTable and GraphQLFieldtypePageTableNext

Install (Short way)

  1. Copy the files for this module to /site/modules/PageTableNext/ and Install PageTableNext, FieldtypePageTableNext and InputfieldPageTableNext.
  2. Enter your favorite field name and click "Setup Field" in Module Configuration.
  3. Add the field to your page template and add some content element templates to the PageTableNext field.

Install (Long way)

  1. Copy the files for this module to /site/modules/PageTableNext/ and Install PageTableNext, FieldtypePageTableNext and InputfieldPageTableNext.
  2. Create a new template (e.g. "content-elements").
    • In the tab "Access" set the permission management to "Yes", then check "View page" and "Guest".
    • Optional: In the tab "Family" set the option "Can this template be used for new pages?" to "One".
    • Optional: In the "Advanced" tab, check the options "Don't allow pages to change their template?" and "Don't allow unpublished pages".
  3. Create a new page which will act as a container for the content elements (as child of Admin) with the title e.g. "Content Elements". Choose the template from step 2 ("content-elements")
  4. Create a new field of type PageTableNext (e.g. ptn)
    • "Details" tab
      • Select one or more templates for your content elements under "Select one or more templates for items".
      • Optional: In "Select a parent for items" select the container page you created in step 3.
      • Optional: Configure the following at "Page behaviors":
        • Delete: Delete them
        • Trash: Nothing
        • Unpublish: Nothing
    • "Input" tab
      • Optional: For "Automatic Page Name Format" add {template.label|template.name}.
      • Path to content element templates: Add the path for the front- and backend rendering of the content elements. The path is relative to /site/templates/fields/ e.g. "ptn/". The name of the PHP template file must match the name of the template.
  5. Copy the file from the module folder /site/modules/PageTableNext/data/ptn.php to the folder /site/templates/fields/[fieldname].php. Replace "ptn" with your field name
  6. Add the field to your page template and add some content element templates to the new PageTableNext field.

Install via composer

  1. Execute the following command in your website root directory.
    composer require nr/pagetablenext
    

Rendering

Frontend

Use file field rendering for the output. You can find more information here.

// if your field name is "ptn":
echo $page->render->ptn;

Backend

All elements are rendered in the backend as custom HTML elements (<ptn-content>). The styling is separated from the backend. This way, the rendering of your content elements is encapsulated and separated from the backend. You can use a different custom element by extending the class "PtnContent".

class PtnContent extends HTMLElement {
	constructor() { /* some code here*/ }
}

customElements.define('ptn-content', PtnContent);

Configuration / Add news fields

Modules > Configure > PageTableNext

Field settings

Fields > ptn > Details

Select one or more templates for items

Here you can select templates for the content elements. These templates are available later when you want to create new content elements on your page.

Select a parent for items

If selected, all new content elements are stored as a child page of the selected page. If no page is selected, the content elements will be created as child pages of the referenced page.

Fieldsettings

API

The field itself returns a PageArray of content elements. If you want you can create your own rendering:

/** @var PageArray $contentElements */
$contentElements = $page->ptn;
$renderIndex = 0;

/** @var Page $contentElement */
foreach($contentElements as $contentElement) {
    echo $page->renderValue(
        $contentElement->set('_myRenderIndex', $renderIndex++),
        'ptn/' . $contentElement->template->name
    );
}

Preview loading

Fields > ptn > Input > Preview loading

Like the dynamic loading of repeaters, the backend previews are loaded when they are needed:

  • Preload on hover (default): the page loads without rendering the previews, a preview is requested via ajax when the pointer rests on a content element (150 ms) or when it is opened, so opening is usually instant.
  • Load when a content element is opened: previews are only requested the first time their content element is opened.
  • Render all previews with the page: the previous behaviour.

The preview markup comes from ptn-preview.php (overridable like the other files). Whenever a preview has been attached to its shadow root (rendered with the page or loaded lazily), <ptn-content> dispatches the event ptn:preview-loaded (bubbles, composed), e.g. to initialize Alpine in the shadow root:

document.addEventListener('ptn:preview-loaded', e => Alpine.initTree(e.target.shadowRoot));

Defaults of new fields

A new PageTableNext field gets the visibility "Always open" (Inputfield::collapsedNever), the content elements have their own open/collapse. It is applied once when the field is created and can be changed in the field settings. Hook PageTableNext::getNewFieldDefaults to change the defaults:

$wire->addHookAfter('PageTableNext::getNewFieldDefaults', function(HookEvent $event) {
	$event->return = array_merge($event->return, ['collapsed' => Inputfield::collapsedNo]);
});

Admin theme settings

The field respects the settings of AdminThemeUikit (Fields > ptn > Input):

  • Color (primary, highlight, warning …): the content elements get the block background, so they stand out on the colored field.
  • Border and Offset: applied to the field wrapper by the theme.
  • Input size (global setting of AdminThemeUikit, small/large): denser or roomier content elements.
  • Visibility "locked" (read only): the content elements can be opened to see their previews, actions, sorting and add buttons are hidden.

Customize the backend

Most customizations need no copied template file. Use hooks (e.g. in /site/ready.php) and keep getting the improvements of new module versions:

What How
Label of a content element hook PageTableNext::getContentElementTitle
Additional info in the header (status, dates …) hook PageTableNext::getContentElementTitlePostfix
Add, remove or reorder actions hook InputfieldPageTableNext::getContentElementActions
Stylesheets of the preview /site/templates/PageTableNext/content.css or hook InputfieldPageTableNext::getPreviewStylesheets
Scripts in the preview (Alpine …) JS event ptn:preview-loaded
Own JavaScript (custom actions …) /site/templates/PageTableNext/ptn.php

Styling

Copy your CSS file to /site/templates/PageTableNext/content.css or set a symlink to your style file:

cd site/templates/PageTableNext/
ln -s path/to/your/style.css content.css

Or use the stylesheets of your frontend build (the hook gets the content element, the field is $event->object->hasField):

$wire->addHookAfter('InputfieldPageTableNext::getPreviewStylesheets', function(HookEvent $event) {
	$file = 'dist/main.css';
	$event->return = [$event->config->urls->assets . $file . '?modified=' . filemtime($event->config->paths->assets . $file)];
});

Add custom actions

Actions are an array, a hook can add, remove or reorder them (keys: icon Font Awesome name without fa-, title, class, custom (name and params of your JS action), optional href, visibility, hidden, attrs):

$wire->addHookAfter('InputfieldPageTableNext::getContentElementActions', function(HookEvent $event) {
	/** @var Page $contentElement */
	$contentElement = $event->arguments(0);
	$actions = $event->return;

	// before "delete"
	$delete = $actions['delete'] ?? null;
	unset($actions['delete']);
	$actions['myaction'] = [
		'icon' => 'bolt',
		'title' => __('My Custom Action'),
		'custom' => ['name' => 'myaction', 'params' => $contentElement->id],
		'visibility' => 'hover', // optional: only on hover (always visible on touch devices)
	];
	if($delete) $actions['delete'] = $delete;

	unset($actions['copy'], $actions['insert'], $actions['uncopy']); // e.g. no clipboard
	$event->return = $actions;
});

This renders (the same markup works in a customized ptn-content.php):

<a class="ptn_action ptn_actions_custom" data-action="myaction" data-visibility="hover"
   data-actioncustom='{"name":"myaction","params":1234}' href="#" title="My Custom Action"><i class="fa fa-fw fa-bolt"></i></a>

While an action runs, its icon pulses and further clicks are ignored. Custom actions can use this too: this.setBusy(event.currentTarget, true) … this.setBusy(event.currentTarget, false).

Register your action e.g. in the file ptn.php. No jQuery is required.

<script>
	PageTableNext.actions.actionMyaction = function (params, event) {
		/** PointerEvent, event.currentTarget is the clicked button */
		const clickEvent = event;

		/** mixed (your custom parameter) */
		const myParams = params;

		/** PageTableNext.ContentElement (this.el is the table row) */
		const contentElementInstance = this;

		/** PageTableNext.Field (this.getParent().el is the <ptn-field> element) */
		const table = this.getParent();
	}
</script>

The old registration $.InputfieldPageTableNextContentElementCustomActions.actionMyaction = ... is deprecated (marked with @deprecated, so IDEs show it) but still works when jQuery is loaded (it is an alias of PageTableNext.actions).

Set "prevents": false in data-actioncustom if the click should not be stopped.

Override template files

For changes a hook can't do, all files in /site/modules/PageTableNext/templates/ can be overridden: create the folder /site/templates/PageTableNext and copy the corresponding files there.

Each file has a revision in its docblock (@ptn-template 2). It is raised when the file changes in a way your copy should follow. Modules > Configure > PageTableNext > Template overrides lists your copies and marks those with a lower revision (copies without the tag count as revision 1) as outdated; after a module update a warning is shown. Merge the changes of the module's file, then raise the revision in your copy.

UPGRADE-OVERRIDES.md describes step by step how to replace an old ptn-content.php by hooks (written as instructions for an AI coding agent, works for humans too).

A customized ptn-content.php from an older version renders the previews with the page; move the preview part to ptn-preview.php to use lazy loading.

Extend Custom Element

Usually the event ptn:preview-loaded is enough. To use your own custom element anyway, extend PtnContent (e.g. in ptn.php), override ptn-content.php and change the tag name from <ptn-content> to <my-content>:

class MyContent extends PtnContent {
	loaded() {
		super.loaded();
		// your code, this.shadowRoot contains the preview
	}
}
if(!customElements.get('my-content')) customElements.define('my-content', MyContent);

AdminThemeBridge

The Inputfield implements Bridge's BridgeComponent contract, so pages with PageTableNext fields run without the jQuery stack under AdminThemeBridge. If your customized ptn.php contains an inline script that uses jQuery, the module tells Bridge to load the jQuery stack on that page. Register actions with PageTableNext.actions to stay jQuery-free.

JavaScript API

The field markup is wrapped in a <ptn-field> custom element, which initializes itself (also when the field is loaded via ajax). Modals, confirm dialogs and sorting are provided by the admin theme (AdminThemeBridge or AdminThemeUikit) through PageTableNext.ui.

// get the instance of a field or a content element
const field = PageTableNext.get(document.querySelector('ptn-field'));
const contentElement = PageTableNext.get(rowOrChildElement);

field.reload();                       // reload the content elements
field.getContentElements();           // array of PageTableNext.ContentElement
contentElement.actionToggleCollapse();

// all fields listen to this event (e.g. after the clipboard changed)
document.dispatchEvent(new CustomEvent('ptn:update'));

The toolbar (expand/collapse all, hide/show unpublished) is shown in the header of the field, next to the open/collapse icon. Without a visible header (e.g. "skip label") it stays above the content elements.

Upgrade notes (jQuery free version)

  • The field markup is wrapped in <ptn-field> and initialized by it, $('.InputfieldPageTableNext').inputfieldPageTableNext() no longer exists.
  • Register custom actions with PageTableNext.actions. The jQuery aliases $.InputfieldPageTableNextContentElementCustomActions / $.InputfieldPageTableNextCustomAction and the $context, $table, … getters of the instances are deprecated (@deprecated in the JSDoc) and only work while jQuery is loaded.
  • The markup classes inherited from the core PageTable were renamed, so code written for the core PageTable (e.g. AdminThemeBridge's native PageTable) no longer handles PageTableNext fields. Update your own CSS/JS if you used them:
Before Now
.InputfieldPageTableContainer .InputfieldPageTableNextContainer
.InputfieldPageTableAdd .InputfieldPageTableNextAdd
.InputfieldPageTableButtons, .InputfieldPageTableButtonsColumn .InputfieldPageTableNextButtons, .InputfieldPageTableNextButtonsColumn
.InputfieldPageTableSort, .InputfieldPageTableDelete .InputfieldPageTableNextSort, .InputfieldPageTableNextDelete
.InputfieldPageTableOrphans, .InputfieldPageTableOrphansAll .InputfieldPageTableNextOrphans, .InputfieldPageTableNextOrphansAll
  • Action icons use Font Awesome (<i class="fa fa-…">) instead of uk-icon.
  • The backend list looks like the repeater items of the admin theme (drag handle, controls on hover, add links). Action links use the class ptn_action instead of uk-icon-button; the chevrons are wrapped in .ptn_toggle at the start of .ptn_meta.
  • Content elements are sorted by dragging their header .ptn_meta (a click opens/collapses, action links don't start a drag).

Abandoned data

Sometimes it can happen that a page loses the link to a PageTableNext field. It can then be useful to locate this abandoned content

You can use this function to find these abandoned pages.

// find the abandoned page ids as array
$abandonedPageIds = $modules->get('PageTableNext')->findAbandonedPageIds();

// OR

// find the abandoned pages as PageArray and delete
$options = [
    'selector' => 'limit=25, sort=-modified, include=all', // default
    'additionalSelector' => 'modified<now-24month', // example
    'finderOptions' => ['lazy' => true] // default
];
$abandonedPages = $modules->get('PageTableNext')->findAbandonedPages($options);
foreach($abandonedPages as $p) wire()->pages->delete($p);

GraphQL

The content elements can also be queried using GraphQL. For this purpose, the data is divided into three new fields: id, type and render. All other page fields are still available (created, name, references, template ...).

id is the page id of the content element. type is the template name in PascalCase.
render is everything from the content element template file /site/fields/[content-element-template-name].php. This template is also used for the preview in the backend. If you want to use a different template here, e.g. to return different fields or a serialised object, you can create an additional template file with the postfix ".graphql" /site/fields/[content-element-template-name].graphql.php.

Request

query {
    home {
        first {
            id
            name
            title
            ptn {
                getTotal
                list {
                    id
                    type
                    render
                }
            }
        }
    }
}

Response

{
  "data": {
    "home": {
      "first": {
        "id": "1",
        "name": "home",
        "title": "Home",
        "ptn": {
          "getTotal": 2,
          "list": [
            {
              "id": "1193",
              "type": "CeText",
              "template": "ce-text",
              "render": "<h1>Hello World</h1>"
            },
            {
              "id": "1194",
              "type": "CeImage",
              "template": "ce-image",
              "render": "<h1>Nice pictures</h1> <img ....>"
            }
          ]
        }
      }
    }
  }
}

GraphQL GraphQL query with Postman

ToDos

  • Refactor content element handling with Alpine.js
  • Video-Tutorial