torann/snazzy-twig

使用Twig的力量渲染用户模板

0.1.4 2018-04-02 19:38 UTC

This package is auto-updated.

Last update: 2024-09-08 09:18:30 UTC


README

Latest Stable Version Total Downloads

Laravel对Skosh的Twig模板引擎的Laravel实现,用于多租户环境。

安装

Composer

从命令行运行

$ composer require torann/snazzy-twig

服务提供者

您需要扩展内置的服务提供者,以便您可以添加自定义小部件并获得网站实例。为此,在\app\Providers目录中创建一个名为TwigServiceProvider的服务提供者,并像下面这样扩展Snazzy Twig提供者

<?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'];
    }
}

注意:需要getWebsite()方法来获取用于生成视图的网站模型

完成后,您需要将新的服务提供者注册到应用程序中。

Laravel

打开config/app.php,找到providers键。

'providers' => [

    \App\Providers\TwigServiceProvider::class,

]

Lumen

对于Lumen,在bootstrap/app.php中注册服务提供者。

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