Static utility methods

Wireframe provides static utility methods for cases where instantiating an object might be inconvenient, or where they can notably speed up the development workflow. On this page we list included methods, their parameters and return values, and explain how and why you might want to use them.

Static getter (factory) method for Components

Wireframe::component( string $component_name, array $args = [] ) : \Wireframe\Component

Added in Wireframe 0.8.0.

This method accepts a name of a component – such as "Card", assuming that you've created a component with that name first – and the arguments for component as an array, and returns an instance of the component. If the component can't be found, this method will throw a WireException.

Example

<?php foreach ($pages->find('template=member') as $member): ?>
    <?= Wireframe::component('Member', ['item' => $member]) ?>
<?php endforeach; ?>

Note: in the example above we're echoing the returned object directly. This is possible because Component::__toString() returns the rendered markup of the component.

Static getter (factory) method for Pages

Wireframe::page( int|string|Page $source, array|string $args = [] ) : string|Page|NullPage

Added in Wirerame 0.8.0.

This method takes a source parameter – the type of which may be integer (Page ID), string (selector), or ProcessWire Page object – and an array of optional arguments, and attempts to get a ProcessWire Page that can then be rendered using Wireframe. Instead of argument array it's also possible to provide a string, in which case it's assumed to be the name of a view file.

Primary benefit of using this method is that it makes it easy to render pages that haven't already been "connected" to Wireframe using the alternative filename method, as well as pages that don't have a template file and thus couldn't normally be rendered with the Page::render() method.

Note: if a string was provided instead of argument array or the argument array contains index "render" with value `true`, this method returns pre-rendered markup for given page. For all possible arguments see the PHPDoc comments for Wireframe::page().

Example

<ul>
    <?php foreach ($pages->get('template=contacts-bucket')->children('template=contact') as $contact): ?>
        <li><?= Wireframe::page($contact, 'list-item') ?></li>
    <?php endforeach; ?>
</ul>

Above example would render each "contact" Page using view file "list-item" (/site/templates/views/contact/list-item.php).

Back to top