Registering custom view helpers in ZF2

If you want to register custom view helpers with a module you can do so by using the service location built into the Skeleton Application and creating a module config that looks something like.

return array(
    'view_helpers' => array(
        'invokables' => array(
            // generic view helpers
            'truncate' => 'Zucchi\View\Helper\Truncate',

            // form based view helpers
            'bootstrapForm' => 'Zucchi\Form\View\Helper\BootstrapForm',
            'bootstrapRow' => 'Zucchi\Form\View\Helper\BootstrapRow',
            'bootstrapCollection' => 'Zucchi\Form\View\Helper\BootstrapCollection',
        ),
    ),
);

2 thoughts on “Registering custom view helpers in ZF2

  1. Another way would be to define:
    public function getViewHelperConfig () { return array(…); }

    in your Module.php (per module)

    🙂

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.