2017 © Pedro Peláez
 

library smartyprovider

Smarty service provider for silex

image

fractalizer/smartyprovider

Smarty service provider for silex

  • Monday, December 3, 2012
  • by jarolu
  • Repository
  • 1 Watchers
  • 0 Stars
  • 1,402 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 6 Forks
  • 0 Open issues
  • 1 Versions
  • 2 % Grown

The README.md

SmartyServiceProvider

The SmartyServiceProvider provides integration with the [Smarty] (http://www.smarty.net) template engine., (*1)

Parameters

  • smarty.dir (string, optional): Path to the directory containing Smarty distribution (a one with folders libs and demo). If not given, provider assumes, that smarty class is already loaded., (*2)

  • smarty.instance (\Smarty, optional): An instance of Smarty class. If not given, will be created by the provider., (*3)

  • smarty.options (array, optional): An associative array of smarty class variables to set. Check out the [Smarty documentation] (http://www.smarty.net/docs/en/api.variables.tpl) for more information., (*4)

  • smarty.configure (callable, optional): A callable which takes one argument - Smarty class instance. It is called during provider's register() method. You can use this option to make some custom smarty configuration, for example., (*5)

Services

  • smarty: The Smarty instance. The main way of interacting with Smarty.

Registering

Make sure you place a copy of [Smarty] (http://www.smarty.net) in the vendor/Smarty directory:, (*6)

use FractalizeR\Smarty\ServiceProvider as SmartyServiceProvider;
define('SMARTY_PATH', __DIR__ . '/../../../../vendor/Smarty');

$app->register(new SmartyServiceProvider(), array(
          'smarty.dir' => SMARTY_PATH,
          'smarty.options' => array(
                'template_dir' => SMARTY_PATH . '/demo/templates',
                'compile_dir' => SMARTY_PATH . '/demo/templates_c',
                'config_dir' => SMARTY_PATH . '/demo/configs',
                'cache_dir' => SMARTY_PATH . '/demo/cache',),));

Note:, (*7)

Smarty is not compiled into the silex.phar file. You have to add your own copy of [Smarty] (http://www.smarty.net) to your application., (*8)

Usage

The Smarty provider provides a smarty service:, (*9)

$app->get('/hello/{name}', function ($name) use ($app) {
    return $app['smarty']->display('hello.tpl', array(
        'name' => $name,
    ));
});

This will render a file named hello.tpl in the configured templates folder you passed in smarty.options., (*10)

In any Smarty template, the app variable refers to the Application object. So you can access any services from within your view. For example to access $app['request']->getHost(), just put this in your template:, (*11)

{$app.request->getHost()}

The Versions

03/12 2012

dev-master

9999999-dev https://github.com/jarolu/Silex_SmartyServiceProvider.git

Smarty service provider for silex

  Sources   Download

MIT

The Requires

 

The Development Requires

extension silex smarty silex-extension