Skip to content

Additional macros

Roland Toth edited this page Mar 22, 2017 · 35 revisions

The module comes with a few helper macros. If you don't need them you can disable in the module's settings page.

editlink

Renders a link to open the admin and edit the page in question.

Parameters:

  • target: the Page to edit in the admin
  • text: text that appears on the link (default: Edit)
  • class: CSS class (default: edit-link)
  • target: same as the HTML target attribute (defaul: _blank)
{* all parameters: target Page, text to show, CSS class *}
{editlink target => $p, text => 'Edit page', class => 'edit-link', target => '_blank'}

{* Edit link for $p (ProcessWire page) *}
{editlink target => $p}
{editlink $p}

{* Edit link for the page with id 1050 *}
{editlink 1050}

{* Edit link for the current $page *}
{editlink}

The rendered link has no styling, you (the developer) should take care of this.

The macro can't be used as an n:macro.

iff

An IF condition that sets a variable "$x" to the value of the condition. In the example below "$x" will be "$page->body", making easier to replace "body" if you need for example "title" instead.

<div n:iff="$page->body">
    {$x|noescape}
</div>
{iff $page->body}
    {$x|noescape}
{/iff}

minify

Minifies markup by removing whitespace and optionally performs other tweaks. Can be applied partially to sections or individual HTML tags.

By default the macro removes whitespace between HTML tags that are not on the same line to handle situations like bold text followed by italic. This is a safe way to reduce the overall size of the markup.

Experimental features

If the parameter true is passed the macro will perform additional minifications, eg. removing quotes from attributes that has no spaces or removing default attributes like type="text".

Applying as an n:macro:

<div n:minify>
    ...
</div>

Applying as an inner macro to remove whitespace between li elements:

<ul n:inner-minify>
    <li n:foreach="..."></li>
</div>

Applying to a region (whole layout in this example) and enabling experimental settings (by passingtrue):

{minify true}
<!DOCTYPE html>
...
</html>
{/minify}

page

If you need to switch to a page quickly, use the "page" macro. It accepts a page ID (or a selector). It automatically sets the "$p" variable too. Under the hood it uses the $pages->get() API command.

<div n:page="1039">
    {$p->title}
</div>
{page 'template=home'}
    {$p->title}
{/page}

pages

Simlar to the "page" filter but returns a PageArray (loaded to "$pArr") instead of a single page. Under the hood it uses the $pages->find() API command.

<ul n:pages="'template=basic-page,limit=10'" n:inner-foreach="$pArr as $p">
    <li>{$p->title}</li>
</ul>
{pages 'template=basic-page,limit=10'}
<ul n:inner-foreach="$pArr as $p">
    <li>{$p->title}</li>
</ul>
{/pages}

setvar

This is an alternative to the built-in "var" macro and allows setting a variable "inline", that is, adding to a tag for example.

<div n:setvar="url,$p->url">
    {$url}
</div>