torann/snazzy-twig

Render user templates using the power of Twig

0.1.4 2018-04-02 19:38 UTC

This package is auto-updated.

Last update: 2024-05-08 08:27:04 UTC


README

Latest Stable Version Total Downloads

Laravel implantation of Skosh's Twig templating engine for use in a multi-tenant environment.

Installation

Composer

From the command line run:

$ composer require torann/snazzy-twig

The Service Provider

You will need to extend the built in service provider so that you can add your custom widgets and get the website instance. To do this create a service provider named TwigServiceProvider in the \app\Providers directory and extend the Snazzy Twig provider like below:

<?php

namespace App\Providers;

use Torann\SnazzyTwig\TwigServiceProvider as ServiceProvider;

class TwigServiceProvider extends ServiceProvider
{
    /**
     * Twig view widgets.
     *
     * @var array
     */
    protected $widgets = [
        //
    ];
    
    /**
     * Get the current website.
     *
     * @return \Torann\SnazzyTwig\Contracts\WebsiteInterface
     */
    protected function getWebsite()
    {
        return $this->app['website'];
    }
}

Note: the getWebsite() method is needed to get the website model to use for generating the views

Once this is done you need to register the new service provider with the application.

Laravel

Open up config/app.php and find the providers key.

'providers' => [

    \App\Providers\TwigServiceProvider::class,

]

Lumen

For Lumen register the service provider in bootstrap/app.php.

$app->register(\App\Providers\TwigServiceProvider::class);