Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision |
development:plugins:view_helpers [2015/12/11 20:22] – ↷ Links adapted because of a move operation demiankatz | development:plugins:view_helpers [2020/03/13 19:48] – demiankatz |
---|
====== 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. See the [[http://framework.zend.com/manual/current/en/modules/zend.view.helpers.html|Zend Framework 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" ZF application). | ===== 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 [[development:architecture:customizing_vufind#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 <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>). | * 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 <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 [[development:architecture: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. |
* Configure the new helper in the 'helpers' section of the theme.config.php file for your current theme. This is a standard [[http://framework.zend.com/manual/2.0/en/modules/zend.service-manager.quick-start.html|Zend Framework 2 service manager]] configuration with invokables, factories, etc. | * Configure the new helper in the 'helpers' section of the theme.config.php file for your current theme. This is a standard [[https://docs.laminas.dev/laminas-servicemanager/quick-start/|Laminas service manager]] configuration with invokables, factories, etc. |
| |
---- struct data ---- | ---- struct data ---- |
---- | ---- |
| |