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

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
Last revisionBoth sides next revision
vufind2:building_a_view_helper [2012/09/21 17:32] – created demiankatzdevelopment:plugins:view_helpers [2020/03/13 19:48] demiankatz
Line 1: Line 1:
-====== Building a View Helper ======+====== View Helpers ======
  
-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.+===== 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 [[https://docs.laminas.dev/laminas-view/helpers/intro/|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: Creating a view helper is simple:
  
-  * Pick a namespace for your view helpers.  This should usually be inside a [[customizing_vufind_2.0#modules|custom module]]. +  * Pick a namespace for your view helpers.  This should usually be inside a [[development:architecture:customizing_vufind#modules|custom module]]. 
-  * In your chosen namespace, create a class that extends \Zend\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()). +  * In your chosen namespace, create a class that extends \Laminas\View\Helper\AbstractHelper.  You can either implement all of your functionality in the class'<nowiki>__invoke()</nowiki> method (in which case you can use the helper with calls like <nowiki>$this->myHelper()</nowiki>) or else you can leave <nowiki>__invoke()</nowiki> out and add a number of public methods (in which case you can use the helper with calls like <nowiki>$this->myHelper()->myMethod()</nowiki>). 
-  * Create a [[customizing the user interface|custom theme]] if you have not done so already.   +  * Create a [[development:architecture:user_interface|custom theme]] if you have not done so already.   
-  * Specify your helper namespace with the helper_namespace setting in your theme'theme.ini file (all helpers for a given theme should reside in the same namespace). +  * Configure the new helper in the 'helpers' section of the theme.config.php file for your current theme.  This is standard [[https://docs.laminas.dev/laminas-servicemanager/quick-start/|Laminas service manager]] configuration with invokables, factories, etc.
-  * Specify the name of your helper by adding new helpers_to_register[] entry to theme.ini.+
  
 ---- struct data ---- ---- struct data ----
 ---- ----
  
development/plugins/view_helpers.txt · Last modified: 2020/03/19 21:53 by crhallberg