About Features Downloads Getting Started Documentation Events Support GitHub

Love VuFind®? Consider becoming a financial supporter. Your support helps build a better VuFind®!

Site Tools


Warning: This page has not been updated in over over a year and may be outdated or deprecated.
development:plugins:view_helpers

This is an old revision of the document!


View Helpers

Building a View Helper

View helpers are a convenient way of encapsulating logic that is useful during template rendering. All registered view helpers are accessible as methods of $this within templates. See the Laminas manual for more general information. The notes below account for some VuFind-specific details (since VuFind's theme system makes some details slightly different than in a “vanilla” Laminas application).

Creating a view helper is simple:

  • Pick a namespace for your view helpers. This should usually be inside a custom module.
  • In your chosen namespace, create a class that extends \Laminas\View\Helper\AbstractHelper. You can either implement all of your functionality in the class's __invoke() method (in which case you can use the helper with calls like $this->myHelper()) or else you can leave __invoke() out and add a number of public methods (in which case you can use the helper with calls like $this->myHelper()->myMethod()).
  • Create a custom theme if you have not done so already.
  • Configure the new helper in the 'helpers' section of the theme.config.php file for your current theme. This is a standard Laminas service manager configuration with invokables, factories, etc.
development/plugins/view_helpers.1584128903.txt.gz · Last modified: 2020/03/13 19:48 by demiankatz