2017 © Pedro Pelรกez
 

library templator

An awesome Twig wrapper to control your layout like a boss!

image

kristories/templator

An awesome Twig wrapper to control your layout like a boss!

  • Monday, January 27, 2014
  • by Kristories
  • Repository
  • 1 Watchers
  • 9 Stars
  • 15 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 1 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

Templator

An awesome Twig wrapper to control your layout like a boss!

Build Status, (*1)

What Templator can do for you?

  • Focus on position
  • Widget can be displayed in all the positions of a template
  • This will help reduce redundancy and keep you from writing too much code

If you are template designer

The template designer has complete control over block positions., (*2)

1, (*3)

<!DOCTYPE html>
<html lang="en">
<head>
    <title>{{ title }}</title>
</head>
<body>
    {% block header %}{% endblock %}
    {% block left %}{% endblock %}
    {% block content %}{% endblock %}
    {% block right %}{% endblock %}
    {% block footer %}{% endblock %}
</body>
</html>

If you are developer

Developer has complete control widgets you want to appear in block positions., (*4)

$templator->blocks(array(
    'position' => array('widget')
));

Let see how it goes

2, (*5)

$templator->blocks(array(
    'header'    => array('widget_a'),
    'left'      => array('widget_b'),
    'right'     => array('widget_c'),
    'footer'    => array('widget_d')
));

3, (*6)

$templator->blocks(array(
    'header'    => array('widget_a'),
    'right'     => array('widget_c'),
    'footer'    => array('widget_d')
));

4, (*7)

$templator->blocks(array(
    'header'    => array('widget_a'),
    'right'     => array('widget_b', 'widget_c', 'widget_e', 'widget_f'),
    'footer'    => array('widget_d')
));

Installation

Add the following into your composer.json file:, (*8)

{
    "require": {
        "kristories/templator": "*"
    }
}

Then run, (*9)

composer install

Usage

Basic

$templator = new \Templator\Templator();

// Set data
$templator->data('foo', 'bar');

// Set widgets
$templator->blocks(array(
    'header' => array('logo', 'search')
));

// Render
// base_template    => /templates/base/base_template.html
// page             => /templates/pages/page.html
echo $templator->render('base_template', 'page');

Config

$templator = new \Templator\Templator(array(
    'path'  => array(
        'root'      => 'templates',
        'base'      => 'base',
        'pages'     => 'pages',
        'widgets'   => 'widgets'
    ),
    'cache' => NULL
));

Structure :, (*10)

โ”œโ”€โ”€ templates/
|   โ”œโ”€โ”€ base/
|   |   โ””โ”€โ”€ base_template.html
|   โ”œโ”€โ”€ pages/
|   |   โ”œโ”€โ”€ home.html
|   |   โ”œโ”€โ”€ about.html
|   |   โ”œโ”€โ”€ contact.html
|   |   โ””โ”€โ”€ ...
|   โ””โ”€โ”€ widgets/
|   |   โ”œโ”€โ”€ logo.html
|   |   โ”œโ”€โ”€ menu.html
|   |   โ”œโ”€โ”€ tags.html
|   |   โ”œโ”€โ”€ search.html    
|   |   โ””โ”€โ”€ ...
โ””โ”€โ”€ cache/

Data

$templator->data('foo', 'bar');
// or
$templator->data(array(
    'foo' => 'bar',
    'bar' => 'baz'
));

Widgets

$templator->blocks(array(
    'header' => array('logo', 'mainmenu', 'search'),
    'footer' => array('copyright, 'footermenu')
));

Render

$templator->render('base_template', 'page');

Example

templator-bootstrap, (*11)


Why Twig?

Twig is a modern template engine for PHP

  • Fast: Twig compiles templates down to plain optimized PHP code. The overhead compared to regular PHP code was reduced to the very minimum.
  • Secure: Twig has a sandbox mode to evaluate untrusted template code. This allows Twig to be used as a template language for applications where users may modify the template design.
  • Flexible: Twig is powered by a flexible lexer and parser. This allows the developer to define its own custom tags and filters, and create its own DSL.

The Versions

27/01 2014

dev-master

9999999-dev https://github.com/Kristories/Templator

An awesome Twig wrapper to control your layout like a boss!

  Sources   Download

MIT

The Requires

 

The Development Requires

twig template management

27/01 2014

dev-dev

dev-dev https://github.com/Kristories/Templator

An awesome Twig wrapper to control your layout like a boss!

  Sources   Download

MIT

The Requires

 

The Development Requires

twig template management

27/01 2014

0.0.2

0.0.2.0 https://github.com/Kristories/Templator

An awesome Twig wrapper to control your layout like a boss!

  Sources   Download

MIT

The Requires

 

The Development Requires

twig template management