PHPackages                             noadek/twiggy - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. noadek/twiggy

ActiveLibrary[Templating &amp; Views](/categories/templating)

noadek/twiggy
=============

Twig template engine implementation for Laravel. Allows you to use twig without replacing the default blade templating engine in Laravel 5

v1.0.0(9y ago)335MITPHPPHP &gt;=5.4

Since Sep 28Pushed 9y ago4 watchersCompare

[ Source](https://github.com/noadek/Twiggy)[ Packagist](https://packagist.org/packages/noadek/twiggy)[ Docs](https://github.com/noadek/twiggy)[ RSS](/packages/noadek-twiggy/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (2)Versions (2)Used By (0)

Allows you to use [Twig](http://twig.sensiolabs.org/) without replacing the default blade templating engine in [Laravel 5](http://laravel.com/). Based on Edmundas Kondrašovas [Twiggy for CodeIgniter](https://github.com/edmundask/codeigniter-twiggy)

Requirements
------------

[](#requirements)

Twiggy requires Laravel 5.

Installation
------------

[](#installation)

Require this package with Composer

```
composer require noadek/twiggy
```

Quick Start
-----------

[](#quick-start)

Once Composer has installed or updated your packages you need to register Twiggy with Laravel itself. Open up config/app.php and find the providers key, towards the end of the file, and add the Twiggy Service Provider, to the end:

```
'providers' => [
     ...
                Twiggy\Provider\TwiggyServiceProvider::class,
],
```

Now we will use Artisan to add the new twig config file:

```
php artisan vendor:publish --provider="Twiggy\Provider\TwiggyServiceProvider"
```

Configuration
-------------

[](#configuration)

The `php artisan vendor:publish --provider="Twiggy\Provider\TwiggyServiceProvider"` provides you with a default twiggy.php configuration file located in config directory.

Set up dir structure
--------------------

[](#set-up-dir-structure)

Twiggy follows a specific theme-layout-template structure that helps separates your logic from your views. You can create multiple themes and layouts and switch themes and layout on the fly! By default Twiggy will look for your twig files in a themes folder at the server root (you can change this if you like in the config/twiggy.php file provided). So you should create these directories and files.

1. Create a directory structure:

    ```
    +-{LARAVELAPP}/
    | +-app/
    ...
    | +-themes/
    | | +-default/
    | | | +-layouts/

    ```
2. Create a default layout `index.twig` and place it in layouts folder:

    ```

    		Default layout

            {% block content %}

            {% endblock %}

    ```
3. Create a default template file `index.twig` at the root of `default` theme folder:

    ```
    {% extends _layout %}

    {% block content %}

    	Default template file.

    {% endblock %}

    ```
4. You should end up with a structure like this:

    ```
    +-{LARAVELAPP}/
    | +-themes/
    | | +-default/
    | | | +-layouts/
    | | | | +-index.twig
    | | | +-index.twig

    ```

Usage
-----

[](#usage)

At this point you can now begin using twig. Twiggy basically provides you with various helpers for setting up your views or templates.

You call the twig template like a view but with the twig() helper.

```
//app/Http/routes.php
//twig template themes/hello.twig
Route::get('/', function () {
    return twig('hello');
});
```

Twiggy provides other useful helpers for building a theme-layout-template structure for your views.

### Setting the theme

[](#setting-the-theme)

The default twiggy theme is 'default'. This can be changed in the config/twiggy.php file. To create a new theme, add a new folder with the desired theme name in the themes folder.

Setting your theme on the fly.

```
