Basic functions
The basic functions are used to render styles, scripts and markup for a PAGEGRID page. All functions are available through the $pagegrid variable.
As an example, take a look at the default template file pagegrid-page.php in site/templates/.
renderGrid
To render PAGEGRID markup inside your template, use the renderGrid function. This will render all necessary markup for each item added to your PAGEGRID field and wrap the item in a wrapper element.
<?= $pagegrid->renderGrid($page); ?>
As an alternative to the method above, or if you want to render more than one PAGEGRID field per page, you can call the render function for a specific field like this (assuming you added the fields named "mygrid" and "mygrid2" to your page template).
<!-- render markup for field mygrid -->
<?= $page->mygrid; ?>
<!-- render markup for field mygrid2 -->
<?= $page->mygrid2; ?>
Using more then one PAGEGRID field per page can be useful if you build a custom coded website, where PAGEGRID is only used for some parts of your site.
styles
To render PAGEGRID CSS inside your template, use the styles function. This will load all necessary CSS for the page you provide. This function will also look for .css files inside the block folder. If a .css file with the same name as the rendered block template exists and the file is not already loaded, PAGEGRID will load the .css file automatically.
<?= $pagegrid->styles($page); ?>
scripts
To render PAGEGRID javascript inside your template, use the scripts function. This will load javascript plugins enabled in the module settings (the plugins are optional and not needed to run PAGEGRID). Additionally this function will look for .js files inside the block folder. If a .js file with the same name as the rendered block template exists and the file is not already loaded, PAGEGRID will load the .js file automatically.
<?= $pagegrid->scripts($page); ?>
Backend/Frontend
You can use this variable to check whether the template is rendered in the backend or frontend of your website.
<?php
if( $pagegrid->isBackend() ) {
// render things only for the backend
} else {
// render things only for the frontend
}
?>
noAppendFile
As a default output strategy ProcessWire uses Markup Regions and automatically appends the files "_init.php" and "_main.php" to your template file. While this is a powerful and flexible output strategy in ProcessWire and also works great with PAGEGRID, sometimes you just want to render a single template file with all your markup.
To quickly disable ProcessWire’s automatic append/prepend of file “_init.php” and “_main.php” for a template, you can put this function at the top of your template file. (You don’t have to add this for the block templates, because they have it disabled by default.)
<?= $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.