2017 © Pedro Peláez
 

library views

Smarty and Twig View Parser package for the Slim Framework

image

slim/views

Smarty and Twig View Parser package for the Slim Framework

  • Wednesday, December 10, 2014
  • by silentworks
  • Repository
  • 29 Watchers
  • 313 Stars
  • 606,305 Installations
  • PHP
  • 87 Dependents
  • 0 Suggesters
  • 53 Forks
  • 17 Open issues
  • 6 Versions
  • 4 % Grown

The README.md

Slim Views

This repository contains custom View classes for the template frameworks listed below. You can use any of these custom View classes by either requiring the appropriate class in your Slim Framework bootstrap file and initialize your Slim application using an instance of the selected View class or using Composer (the recommended way)., (*1)

Slim Views only officially support the following views listed below., (*2)

  • Smarty
  • Twig

How to Install

using Composer

Install in your project by running the following composer command:, (*3)

$ php composer require slim/views

Smarty

How to use

<?php
require 'vendor/autoload.php';

$app = new \Slim\Slim(array(
    'view' => new \Slim\Views\Smarty()
));

To use Smarty options do the following:, (*4)

$view = $app->view();
$view->parserDirectory = dirname(__FILE__) . 'smarty';
$view->parserCompileDirectory = dirname(__FILE__) . '/compiled';
$view->parserCacheDirectory = dirname(__FILE__) . '/cache';

Twig

How to use

<?php
require 'vendor/autoload.php';

$app = new \Slim\Slim(array(
    'view' => new \Slim\Views\Twig()
));

To use Twig options do the following:, (*5)

$view = $app->view();
$view->parserOptions = array(
    'debug' => true,
    'cache' => dirname(__FILE__) . '/cache'
);

In addition to all of this we also have a few helper functions which are included for both view parsers. In order to start using these you can add them to their respective view parser as stated below:, (*6)

Twig

$view->parserExtensions = array(
    new \Slim\Views\TwigExtension(),
);

Smarty

$view->parserExtensions = array(
    dirname(__FILE__) . '/vendor/slim/views/Slim/Views/SmartyPlugins',
);

These helpers are listed below., (*7)

  • urlFor
  • siteUrl
  • baseUrl
  • currentUrl

urlFor

Twig, (*8)

Inside your Twig template you would write:, (*9)

{{ urlFor('hello', {"name": "Josh", "age": "19"}) }}

You can easily pass variables that are objects or arrays by doing:, (*10)

<a href="{{ urlFor('hello', {"name": person.name, "age": person.age}) }}">Hello {{ name }}</a>

If you need to specify the appname for the getInstance method in the urlFor functions, set it as the third parameter of the function in your template:, (*11)

<a href="{{ urlFor('hello', {"name": person.name, "age": person.age}, 'admin') }}">Hello {{ name }}</a>

Smarty, (*12)

Inside your Smarty template you would write:, (*13)

{urlFor name="hello" options="name.Josh|age.26"}

or with the new array syntax:, (*14)

{urlFor name="hello" options=["name" => "Josh", "age" => "26"]}

You can easily pass variables that are arrays as normal or using the (.):, (*15)

<a href="{urlFor name="hello" options="name.{$person.name}|age.{$person.age}"}">Hello {$name}</a>

If you need to specify the appname for the getInstance method in the urlFor functions, set the appname parameter in your function:, (*16)

<a href="{urlFor name="hello" appname="admin" options="name.{$person.name}|age.{$person.age}"}">Hello {$name}</a>

siteUrl

Twig, (*17)

Inside your Twig template you would write:, (*18)

{{ siteUrl('/about/me') }}

Smarty, (*19)

Inside your Smarty template you would write:, (*20)

{siteUrl url='/about/me'}

baseUrl

Twig, (*21)

Inside your Twig template you would write:, (*22)

{{ baseUrl() }}

Smarty, (*23)

Inside your Smarty template you would write:, (*24)

{baseUrl}

currentUrl

Twig, (*25)

Inside your Twig template you would write:, (*26)

{{ currentUrl() }}

Smarty, (*27)

Inside your Smarty template you would write:, (*28)

{currentUrl}

Authors

Josh Lockhart, (*29)

Andrew Smith, (*30)

License

MIT Public License, (*31)

The Versions

10/12 2014

dev-master

9999999-dev http://github.com/codeguy/Slim-Views

Smarty and Twig View Parser package for the Slim Framework

  Sources   Download

MIT

The Requires

 

templating extensions slimphp

10/12 2014

0.1.3

0.1.3.0 http://github.com/codeguy/Slim-Views

Smarty and Twig View Parser package for the Slim Framework

  Sources   Download

MIT

The Requires

 

templating extensions slimphp

10/12 2014

dev-develop

dev-develop http://github.com/codeguy/Slim-Views

Smarty and Twig View Parser package for the Slim Framework

  Sources   Download

MIT

The Requires

 

templating extensions slimphp

03/04 2014

0.1.2

0.1.2.0 http://github.com/codeguy/Slim-Views

Smarty and Twig View Parser package for the Slim Framework

  Sources   Download

MIT

The Requires

 

templating extensions slimphp

08/12 2013

0.1.1

0.1.1.0 http://github.com/codeguy/Slim-Views

Smarty and Twig View Parser package for the Slim Framework

  Sources   Download

MIT

The Requires

 

templating extensions slimphp

10/07 2013

0.1.0

0.1.0.0 http://github.com/codeguy/Slim-Views

Twig View Parser package for the Slim Framework

  Sources   Download

MIT

The Requires

 

templating extensions slimphp