2017 © Pedro PelĂĄez
 

library minibase-plugin-twig

This plugins replaces the PHP templating engine with Twig. Great for those who likes twig.

image

pkj/minibase-plugin-twig

This plugins replaces the PHP templating engine with Twig. Great for those who likes twig.

  • Sunday, May 5, 2013
  • by peec
  • Repository
  • 1 Watchers
  • 0 Stars
  • 18 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Twig Plugin for Minibase

Enables Twig based templates. Uses the same interface as Minibase offers for rendering normal PHP views. Also includes custom blocks, filters and functions to take the full out of Minibase. Easily do Fragment caching., (*1)

This plugin makes it possible to render .twig and .html files with the Twig templating engine. .php files will still get rendered by the default Minibase view rendering engine., (*2)

Install

{
  "require":{
         "pkj/minibase-plugin-twig": "dev-master"
    }
}

Setup

Setup global view path, we need to know where twig templates are located., (*3)

$mb->setConfig(MB::CFG_VIEWPATH, __DIR__ . '/views');

Init the plugin, (*4)

$mb->initPlugins(array(
    'Pkj\Minibase\Plugin\TwigPlugin\TwigPlugin' => array(
        // Where to store the compiled php templates.       
        'cache' => __DIR__ . '/template_compilation_cache'
    )
));

Start using twig templates., (*5)

Functions

route

Reverse routing is easy., (*6)

Reverse routing:


{{"News.show"|route(32)}} 
Prints forexample: /news/32

{{"News.index"|route()}}
Prints forexample: /news

Check if a route is active:

{% if "News.index"|route().isActive %}
Currently on homepage.
{% endif %}

Filters

asset

Easily add assets, the assets will have the correct base path included., (*7)

<link rel="stylesheet" type="text/css" href="{{"css/style.css"|asset}}" />

Or from a variable
<img src="{{news.img_path|asset}}" />

Tags

cache

Easily cache bits of your view, VERY good if you use a ORM that have lazy loading such as Doctrine!, (*8)

{% cache "uniqueKey1" %}

    Hello I am cached forever!

{% endcache %}


{% cache "uniqueKey2" 3600 %}

    I am cached for 1 hour.

{% endcache %}

The Versions

05/05 2013

dev-master

9999999-dev http://github.com/peec/minibase-plugin-twig

This plugins replaces the PHP templating engine with Twig. Great for those who likes twig.

  Sources   Download

MIT

The Requires