Download the PHP package phpixie/template without Composer
On this page you can find all versions of the php package phpixie/template. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download phpixie/template
More information about phpixie/template
Files in phpixie/template
Package template
Short Description Templating library for PHPixie
License BSD-3-Clause
Homepage http://phpixie.com
Informations about the package template
Template
PHPixie Template uses PHP as the templating language, but can also handle layouts, content blocks, custom extensions and even custom formats. It’s super easy to use it to parse HAML, Markdown or whatever else you like. All you need to do is provide a compiler that will translate your format into a plain PHP template, the library will take care of caching the result, updating it when the files are modified etc. by itself.
Inheritance
It’s pretty inuitive to understand template inheritance, especially if you used Twig or even Smarty. Here is a quick example:
Now lets render it:
You can also include a subtemplate to render a partial:
Template name resolution
Usually templating libraries have some way of providing fallback tempates, that are used if the template you wan’t to use does not exist. And usually they handle it via some naming convention. PHPixie alows you to fine tune name resolutiion using 3 locator types:
- Directory – Maps template name to a folder location, simplest one
- Group – allows you to specify an array of locators. The template will be searched in those locators one by one until it’s found. This is used for providing fallbacks
- Prefix – allows you to route the resolution based on a prefix
This sounds more complex then it actually is, so let’s look at an example, assume the following config:
It means that Site::layout template will be searched for in the site/ folder, while the Theme::home one will be searched for in templates/ and fallback/.
When using the PHPixie Framework you define your locator in the
templateLocator.php
configuration file. Your locator will be prefixed using the name of your bundle.
Extensions
Extensions provide additional methods that you may use inside your views, they are helpful for things like formatting and escaping. As an example let’s look at the HTML extension:
Your Extensions then have to be injected in the library constructor just like Formats.
Creating a custom format
So let’s try integrating it with Markdown, we’ll use mthaml/mthaml for that:
And here is our compiler:
And now let’s inject it into Template:
That’s it, we can now use HAML for our templates while retaining all the original features like Extensions and inheritance.