shapecode / twig-string-loader-bundle
为 twig 添加字符串加载器
3.0.0
2023-12-02 15:25 UTC
Requires
- php: ^8.1
- shapecode/twig-string-loader: ^2.0
- symfony/config: ^5.4 || ^6.4 || ^7.0
- symfony/dependency-injection: ^5.4 || ^6.4 || ^7.0
- symfony/framework-bundle: ^5.4 || ^6.4 || ^7.0
- symfony/http-kernel: ^5.4 || ^6.4 || ^7.0
- symfony/twig-bundle: ^5.4 || ^6.4 || ^7.0
- symfony/yaml: ^5.4 || ^6.4 || ^7.0
Requires (Dev)
- doctrine/coding-standard: ^12.0
- icanhazstring/composer-unused: ^0.8
- maglnet/composer-require-checker: ^4.7
- phpstan/phpstan: ^1.10
- phpstan/phpstan-deprecation-rules: ^1.1
- phpstan/phpstan-phpunit: ^1.3
- phpstan/phpstan-strict-rules: ^1.5
- phpunit/phpunit: ^10.5
- roave/security-advisories: dev-master
- squizlabs/php_codesniffer: ^3.7
- symfony/var-dumper: ^7.0
README
安装说明
首先,您需要将 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' ));