shapecode/twig-string-loader-bundle

为 twig 添加字符串加载器

3.0.0 2023-12-02 15:25 UTC

README

paypal

PHP Version Latest Stable Version Latest Unstable Version Total Downloads Monthly Downloads Daily Downloads License

安装说明

首先,您需要将 shapecode/twig-string-loader-bundle 添加到 composer.json

通过执行 composer require shapecode/twig-string-loader-bundle 或手动操作来实现

{
   "require": {
        "shapecode/twig-string-loader-bundle": "^2.0"
    }
}

您还必须将 ShapecodeTwigStringLoaderBundle 添加到您的 AppKernel.php ...

<?php

// app/AppKernel.php
//...

class AppKernel extends Kernel
{
    //...
    public function registerBundles()
    {
        $bundles = array(
            ...
            new Shapecode\Bundle\TwigStringLoaderBundle\ShapecodeTwigStringLoaderBundle(),
        );
        //...

        return $bundles;
    }
    //...
}

... 或者当您不使用 Symfony Flex 时,添加到 bundles.php

<?php

// bundles.php
//...

return [
    // .....  
    Shapecode\Bundle\TwigStringLoaderBundle\ShapecodeTwigStringLoaderBundle::class => ['all' => true],
];

使用方法

现在您可以使用 twig 编译字符串了

<?php

$this->get('twig')->render('Hello {{ world }}', array(
    'world' => 'World'
));