API Reference
The $pagegrid variable is your primary interface for rendering markup, managing assets, and handling logic. These methods are available globally in your ProcessWire template files.
For a practical example of these functions in action, see the default pagegrid-page.php file in your site/templates/ folder.
Required Core Functions
These three functions are required to render the styles, scripts, and markup for a PAGEGRID field.
renderGrid($page)
To render PAGEGRID markup inside your template, use the renderGrid function. This outputs all necessary HTML for each item in your PAGEGRID field, wrapped in a container.
- Returns: string (HTML markup)
<?= $pagegrid->renderGrid($page); ?>
If you have multiple PAGEGRID fields on one page (e.g., mygrid and mygrid2), you can render them specifically:
<?= $page->mygrid; ?>
<?= $page->mygrid2; ?>
Using multiple fields is useful for custom-coded sites where PAGEGRID is only used for specific sections.
styles($page, $loadDefaults = true)
Renders the CSS required for the page. This function automatically detects and loads .css files located in your block folders if they match the block template name.
- Returns: string (HTML
<link>and<style>tags)
<?= $pagegrid->styles($page); ?>
Advanced: Load the styles for a specific PAGEGRID item, skipping core styles. Useful if you've already loaded PAGEGRID core styles and just want to render the styles for a specific block.
<?php
$header = $pages->get('pg_group_3224');
echo $pagegrid->styles($header, 0);
?>
scripts($page)
Renders the JavaScript required for the page, including enabled plugins. It also automatically detects and loads .js files in your block folders that match the block template name.
- Returns: string (HTML
<script>tags)
<?= $pagegrid->scripts($page); ?>
Utility Functions
renderItem($page)
This function renders a single PAGEGRID item. It is a versatile tool used in two main scenarios:
A. Within Block Templates (Nesting) Use it to render child items inside a parent block (e.g., for sliders, accordions, or tabs). This ensures children maintain their own wrapper and PAGEGRID features like drag-and-drop.
B. Within Page Templates (Cross-rendering) Use it to "pull" a specific block from another page and render it anywhere in your template. This is useful for shared headers, footers, or call-to-action blocks managed on a central page.
- Returns: string (HTML markup for the specific item)
<?php
// Example: Get a specific block from another page by its ID or name
$header = $pages->get('pg_group_3224');
echo $pagegrid->styles($header);
echo $pagegrid->renderItem($header);
echo $pagegrid->scripts($header);
?>
getPage($page)
In PAGEGRID block templates, the $page variable refers to the block item itself. Use this function to access the actual ProcessWire page where the grid is hosted.
- Returns: Page (The parent ProcessWire Page object)
// inside a block template file $page refers to the block item.
// Use this function to get the main page that has your pagegrid field.
$mainPage = $pagegrid->getPage($page);
isBackend()
Check whether the template is being rendered within the ProcessWire admin (backend) or on the live site (frontend). This is useful for hiding/showing specific edit-only markup.
- Returns: boolean
<?php
if( $pagegrid->isBackend() ) {
// render things only for the backend
} else {
// render things only for the frontend
}
?>
noAppendFile($page)
As a default ProcessWire automatically includes _init.php (prepend) and _main.php (append) files. The _main.php usually has your html structure and the _init.php is used for shared functions.
Place this at the very top of your template file to disable these automatic inclusions for that specific template. This is useful if you want to define the html structure in one template file.
<?= $pagegrid->noAppendFile($page); ?>
Alternatively uncomment the lines $config->prependTemplateFile and $config->appendTemplateFile in the config.php file off your site folder to deactivate this globally.