Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

View replacement for the default Laravel View using the Twig template engine.

branch: master

This branch is 0 commits ahead and 0 commits behind master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 config
Octocat-spinner-32 README.md
Octocat-spinner-32 REFERENCE.md
Octocat-spinner-32 twigfunctions.php
Octocat-spinner-32 view.php
README.md

Laravel Twig - Laravel View Replacement

Laravel Twig is a clone of TwigView which replaces the default Laravel View class with the Twig Template Engine.

We use Composer and the composer bundle to fetch the Twig library.

Install Composer

Install composer inside your project directory

curl -s http://getcomposer.org/installer | php

Create a composer.json file at the root of your project

{
    "require": {
        "php": ">=5.3.0",
        "twig/twig": "1.11.*"
    }
}

Install your composer packages, which will install the Twig library files in your vendor/ directory.

php composer.phar install  

Install the Twig bundle

php artisan bundle:install twig

That should install the composer bundle as well since its a dependancy.

In the application/bundles.php file, register the Composer and Twig bundles.

return array(
    'composer' => array('auto' => true),
    'twigview' => array(
    'location' => 'twig', 'autoloads' => array(
        'map' => array(
            'TwigView\\View' => '(:bundle)/view.php',
            )
        )
    ),
);

Replace the View alias (optional)

In the application/config/application.php file, replace the alias with the following:

'aliases' => array(
    ...
    'View' => 'TwigView\\View',
);

If you leave the alias as-is, you can still call \TwigView\View in your controllers.

Usage

All your views must have the .twig file extension. You can use the TwigView\View object in the same manner as the Laravel\View object. Just keep in mind that you are using Twig syntax inside your views.

For example call the Twig view like this

$data = array('message' => 'Hello');
return \TwigView\View::make('home.index', $data);

If you aliased TwigView you can do this

$data = array('message' => 'Hello');
return View::make('home.index', $data);

and in your home/index.twig do this

{{ message }}

Upgrading

To upgrade change the Twig version to in the composer.json file at the root of your project

{
    "require": {
        "php": ">=5.3.0",
        "twig/twig": "1.11.*" 
    }
}

Update using Composer

php composer.phar update  

License

Copyright (c) 2012 Amir Khawaja

This software is provided 'as-is', without any express or implied warranty. In no event will the author be held liable for any damages arising from the use of this software.

Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:

  • The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
  • Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
  • This notice may not be removed or altered from any source distribution.

Thanks

A special thank you to @michaelenger of mustacheview for the inspiration.

Something went wrong with that request. Please try again.