2017 © Pedro Peláez
 

symfony1-plugin axis-hybrid-templating-plugin

symfony 1.x plugin that enables to use multiple templating engines with symfony.

image

axis/axis-hybrid-templating-plugin

symfony 1.x plugin that enables to use multiple templating engines with symfony.

  • Monday, October 6, 2014
  • by 7heaven
  • Repository
  • 1 Watchers
  • 1 Stars
  • 14 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

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)

The Versions

06/10 2014

dev-master

9999999-dev https://github.com/e1himself/axis-hybrid-templating-plugin

symfony 1.x plugin that enables to use multiple templating engines with symfony.

  Sources   Download

MIT

The Requires

 

templating symfony