2017 © Pedro Peláez
 

library lib-template

Template library of the Ride framework.

image

ride/lib-template

Template library of the Ride framework.

  • Friday, October 7, 2016
  • by ride-user
  • Repository
  • 7 Watchers
  • 0 Stars
  • 3,050 Installations
  • PHP
  • 15 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 12 Versions
  • 2 % Grown

The README.md

Ride: Template Library

Template abstraction library of the PHP Ride framework., (*1)

What's In The Library

Engine

The implementation of Engine will implement the actual template engine through the Template interface. A template engine decides the features and the syntax (or language) to write in., (*2)

EngineModel

An EngineModel is an interface for the data store of the available template engines., (*3)

Theme

Optional support for template themes through the Theme interface. Each theme can implement it's own version of a template. This makes it possible to return a different representation of the same data., (*4)

A theme chooses the engines it's available in., (*5)

You can make a theme hierarchical by defining it's parent. This makes it easy to create subthemes and helps the engine to fallback when a resource could not be found., (*6)

ThemeModel

A ThemeModel is an interface for the data store of the available themes., (*7)

Template

A Template instance defines the resource and the variables to render the template. With a ThemedTemplate, you can specify a template in a specific theme., (*8)

The resource should be generic so it's not bound to a specific template engine. For example: use base/index instead of view/smarty/themes/bootstrap/base/index.tpl., (*9)

Code Sample

Check this code sample to get an idea of this library:, (*10)

<?php

use ride\library\template\engine\EngineModel;
use ride\library\template\engine\ThemeModel;
use ride\library\template\TemplateFacade;

function foo(EngineModel $engineModel, ThemeModel $themeModel) {
    $resource = 'path/to/resource';
    $variables = array('var1' => 'value1');

    // template facade should be made available by your implementation
    $templateFacade = TemplateFacade($engineModel, $themeModel);
    $templateFacade->setDefaultEngine('smarty');
    $templateFacade->setDefaultTheme('my-theme');

    // a simple template rendering
    $template = $templateFacade->createTemplate($resource, $variables);
    $template->set('var2', 'value2');

    $output = $templateFacade->render($template);

    // a template for a non-default theme
    $template = $templateFacade->createTemplate($resource, $variables, 'overriden-theme');

    // a template for a non-default theme with a specific engine
    $template = $templateFacade->createTemplate($resource, $variables, 'overriden-theme', 'my-engine');

    // get the file representation of a specific template
    $file = $templateFacade->getFile($template); // ride\library\system\file\File

    // get's the available template for a specific namespace
    $engine = null;
    $theme = null;
    $templates = $templateFacade->getFiles('path/to', $engine, $theme);
    echo $engine; // smarty
    echo $theme; // my-theme

    // reads the meta from the template comments in the beginning of the resource
    // syntax: [key: value([; key: value])*]
    // eg for Smarty: {* name: My Title; action: index *}
    // will return array('name' => 'My Title', 'action' => 'index')
    $meta = $templateFacade->getTemplateMeta($template);
}

Implementations

For more examples, you can check the following implementations of this library: - ride/lib-template-php - ride/lib-template-smarty - ride/lib-template-twig - ride/app-template-php - ride/app-template-smarty - ride/app-template-twig, (*11)

Installation

You can use Composer to install this library., (*12)

composer require ride/lib-template

The Versions

07/10 2016

dev-master

9999999-dev

Template library of the Ride framework.

  Sources   Download

MIT

The Requires

 

by Joris Vandeweerd

07/10 2016

dev-develop

dev-develop

Template library of the Ride framework.

  Sources   Download

MIT

The Requires

 

by Joris Vandeweerd

07/10 2016

1.0.2

1.0.2.0

Template library of the Ride framework.

  Sources   Download

MIT

The Requires

 

by Joris Vandeweerd

08/09 2016

1.0.1

1.0.1.0

Template library of the Ride framework.

  Sources   Download

MIT

The Requires

 

by Joris Vandeweerd

28/06 2016

1.0.0

1.0.0.0

Template library of the Ride framework.

  Sources   Download

MIT

The Requires

 

by Joris Vandeweerd

06/01 2015

0.6.1

0.6.1.0

Template library of the Ride framework.

  Sources   Download

MIT

by Joris Vandeweerd

19/11 2014

0.6.0

0.6.0.0

Template library of the Ride framework.

  Sources   Download

MIT

by Joris Vandeweerd

18/09 2014

0.5.0

0.5.0.0

Template library of the Ride framework.

  Sources   Download

MIT

by Joris Vandeweerd

27/04 2014

0.4.0

0.4.0.0

Template library of the Ride framework.

  Sources   Download

MIT

by Joris Vandeweerd

11/12 2013

0.3.0

0.3.0.0

Template library of the Pallo framework.

  Sources   Download

MIT

by Joris Vandeweerd

26/11 2013

0.2.0

0.2.0.0

Template library of the Pallo framework.

  Sources   Download

MIT

by Joris Vandeweerd

24/10 2013

0.1.0

0.1.0.0

Template library of the Pallo framework.

  Sources   Download

MIT

by Joris Vandeweerd