AxisHybridTemplatingPlugin
This plugin allows you to use different templating engines with symfony 1.x simultanously with
fallback in order of priority., (*1)
For example you can specify PHP template for applicaiton layout decorator and Twig template
for action view., (*2)
Installation
Use Composer. Just add this dependency to your composer.json
:, (*3)
"require": {
"axis/axis-hybrid-templating-plugin": "dev-master"
}
Configuration
To enable Hybrid Templating in your project you should configure symfony to use Hybrid views
for layouts and partials using module.yml
config file:, (*4)
all:
view_class: \Axis\S1\HybridTemplating\View\Hybrid # means HybridView class
partial_view_class: \Axis\S1\HybridTemplating\View\Hybrid # means HybridPartialView class
That's all., (*5)
By default the only enabled templating engine is PHP. You can enable other templating engines
following instructions beyond., (*6)
Templating engines priorities
Sometimes you'll have situations when there is more than one template for a given partial or
controller view available in your project. So there is a questin what will be loaded first.
To control the templating engines priority you can use priority
option of Hybrid Templating Loader
in your project's factories.yml
file., (*7)
hybrid_templating.loader:
parameters:
priority: [twig, php] # these are extensions of supported templating engines in order of priority
or, (*8)
hybrid_templating.loader:
parameters:
priority:
twig: 100 # highest priority > will be checked first
php: 1 # lowest priority > will be checked last
This configuration leads to unambiguous template loader order controlled by you.
By default templating engines are checked in order they were defined in factories.yml
file., (*9)
Note: This way of factories.yml
configuration is supported by
AxisServiceContainerPlugin, (*10)
Twig
To use Twig templating engine you should include
axis/axis-twig-plugin
into your project. Just add dependency to it in your composer.json
:, (*11)
"require": {
"axis/axis-twig-plugin": "dev-master"
}
Next you should configure Twig engine for Hybrid Templating. Add this to your project's factories.yml
:, (*12)
all:
hybrid_templating.engine.twig:
class: \Axis\S1\HybridTemplating\Engine\TwigTemplatingEngine
parameters:
twig: context://twig
tag: hybrid_templating.engine
Usage examples
Imagine you have an application:, (*13)
apps/
- hybrid/
- config/
- app.yml
- module.yml
- routing.yml
- settings.yml
- modules/
- homepage/
- actions/
- actions.class.php
- templates/
- _partial.twig
- indexSucces.php
- templates/
- layout.twig
As you have noticed your controller view is using PHP templating while layout and partial are Twig templates.
This will work transparently switching between templating engines contexts passing specified variables between
templates., (*14)