Item Plugins

RepeaterFlex uses a plugin concept to define Repeater items and implements required rendering code in one place. The most simple plugin only implements a method returning some static information and a rendering function returning the output. This minimalistic example outputs an ordinary horizontal ruler:

<?php namespace ProcessWire;
class HorizontalRuler extends RepeaterFlexItem {
    public static function getModuleInfo() {
        return array(
            'title' => __('Horizontal Ruler only', __FILE__), // Module Title
            'version' => 1,
    public function render(Page $pg) {
        return '<hr/>';

Any item plugin is required to extend the baseclass RepeaterFlexItem and implement a static method getModuleInfo to provide information about the plugin, which is, at least, its title and ideally a version number (which currently is not used anywhere).

The render method must return the markup for this item, which, in most cases, evaluates the Page variable. The calling parameter given as Page refers to the particular repeater item to be rendered and the method probably accesses its fields.

Plugin with datafields

A more useful plugin has at least one or more inputfields which are filled with information in the backend and used from the render method to generate the frontend markup. For best flexibility and re-use of implementation, the fields are declared as an associative array and returned from a method getFields:

    public static function getFields() {
        'paragraph_type' => [
            'context' => [
                'columnWidth' => 25,
            'setup' => [    // may be used to create fields automatically
                'type' => 'FieldtypeOptions',
                'label' => __('Paragraph Type'),
                'inputfieldClass' => 'InputfieldSelect',
                'required' => 1,
                'defaultValue' => 'p',
                'initValue' => '',
                'columnWidth' => 25,
                'options' => [
                    1 => 'p|'.__('Standard'),
                    2 => 'h1|'.__('Header1'),
                    3 => 'h2|'.__('Header2'),
                    4 => 'h3|'.__('Header3'),
                    5 => 'h4|'.__('Header4'),
                    6 => 'h5|'.__('Header5'),
        '@TextLine' => [
            'context' => [
                'columnWidth' => 50,
            'hint' => __('Select a field holding a single line of text'),
            'fieldtype' => 'Text',

This example defines two input fields, the first is named paragraph_type the second, prefixed with @, TextLine.

The paragraph_type refers to a real field in ProcessWire. If it does not exist, it will be created on the fly based on the specification in the setup array. In this case it creates an Options field along with the available options and other attributes.

@TextLine, in contrast, does not define a field direct but refers to a field mapping managed by the particular RepeaterFlex field configuration. The hint entry will be displayed with the mapping selector and fieldtype specifies compatible fieldtypes for this field.

The render function may access both fields simply by its name:

    public function render(Page $pg) {
        $parType = $pg->paragraph_type->value;
        return "<{$parType}>{$pg->TextLine}</{$parType}>";

Please note that mapped fields need to begin with an uppercase letter, while regular fields start lowercase.

This section will be completed as time allows...

prepared in 57ms (content 20ms, header 0ms, Menu 24ms, Footer 10ms)