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.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
development:plugins:view_helpers [2015/12/11 20:22] – ↷ Links adapted because of a move operation demiankatz | development:plugins:view_helpers [2020/03/19 21:53] (current) – [Building a View Helper] crhallberg | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== | + | ====== View Helpers |
- | View helpers are a convenient way of encapsulating logic that is useful during template rendering. | + | ===== Building a View Helper ===== |
+ | |||
+ | View helpers are a convenient way of encapsulating logic that is useful during template rendering. | ||
Creating a view helper is simple: | Creating a view helper is simple: | ||
* Pick a namespace for your view helpers. | * Pick a namespace for your view helpers. | ||
- | * In your chosen namespace, create a class that extends \Zend\View\Helper\AbstractHelper. | + | * In your chosen namespace, create a class that extends \Laminas\View\Helper\AbstractHelper. |
* Create a [[development: | * Create a [[development: | ||
- | * Configure the new helper in the ' | + | * Configure the new helper in the ' |
+ | |||
+ | ===== Commonly Used Helpers ===== | ||
+ | |||
+ | ==== Slots ==== | ||
+ | |||
+ | Slots are designed to be the building blocks on interfaces. Their main feature is that they are not overridden once set, meaning you can set some customizations and be sure that they will be displayed in the interface. Slots can hold any kind of data and can also capture buffers to be displayed later. Here are a few examples. | ||
+ | |||
+ | <code php> | ||
+ | $this-> | ||
+ | $this-> | ||
+ | |||
+ | echo $this-> | ||
+ | |||
+ | echo $this-> | ||
+ | </ | ||
+ | |||
+ | <code php> | ||
+ | // --- custom file --- | ||
+ | <?php $this-> | ||
+ | < | ||
+ | < | ||
+ | <?php $this-> | ||
+ | |||
+ | <?php include $this-> | ||
+ | |||
+ | // --- footer.phtml --- | ||
+ | <?php $this-> | ||
+ | < | ||
+ | <?php echo this-> | ||
+ | </ | ||
+ | |||
+ | ^ Method | ||
+ | | set($value) | Save a value, if it's the first value written | | ||
+ | | get([$default]) | Get the contents of a slot or a default if the slot is empty | | ||
+ | | append($value) | Add a string to the end of a slot and after all previous appends | | ||
+ | | prepend($value) | Add a string to the start of a slot and before all previous appends | | ||
+ | | clear() | Empty a slot and return the previous contents | | ||
+ | | start() | ||
+ | | end([$method]) | Ends a buffer capture. Method can be ' | ||
+ | |||
+ | ==== appendScript/ | ||
+ | |||
+ | When you want to add robust functionality to a page without loading lots of JS and CSS on every other page, headScript and headLink are the best way to go about it. | ||
+ | <code php> | ||
+ | $this-> | ||
+ | $this-> | ||
+ | </ | ||
---- struct data ---- | ---- struct data ---- | ||
+ | properties.Page Owner : | ||
---- | ---- | ||
development/plugins/view_helpers.1449865354.txt.gz · Last modified: 2015/12/11 20:22 by demiankatz