Download the PHP package peak/view without Composer
On this page you can find all versions of the php package peak/view. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package view
Peak/View
Fast and minimalist view template engine with macro, helpers and directives.
! Deprecated
This package is mark as deprecated! It may receive bug fixes if needed but that's it. I strongly encourage users to switch to a modern JS front framework instead of using PHP as templating engine.
Installation
This is a standalone package and not provided automatically with peak/framework
Basic usage
A view need at least 2 things:
- A Presentation
- Data (or variables if you prefer)
Example of view templates
layout example:
script example (represented by in your layout):
Render a view
Create a complex Presentation
Macros
Macro are closure that will be bind to your view class instance. They have access to all class properties/methods so they must be used carefully. Macro are ideal for small task.
and in your template view:
Helpers
An helper is a standalone object instance that is callable
. In contrary of macro, helper do not have access to view properties/methods directly but tend to be more maintainable and secure than macro. Helper are ideal for advanced task and can benefit from dependencies injection.
Example of an helper class:
Before you can use it, you'll need to give a function name to your view helper:
and finally, you'll be able to use your helper the same way you use macros
Directives
Directives provide you a simpler and more elegant syntax for writing templates. By default, there is no directive activated in your View. You need to add them to your View instance with setDirectives()
method. The downside of directives is that View must run them after rendering a template, adding an extra compilation step. The more directives you have, the more it take times to render the view . Of course, this side effect can be mitigated with a proper caching solution, but to keep things simple, Peak View doesn't provide one by default.
template.php
It is important to keep in mind that PHP is executed first in your template and directives are compiled/rendered after that.
You can also write you own directive by using .