moss / twig-bridge
此包已被废弃且不再维护。没有建议的替代包。
moss-twig bridge
2.0
2015-03-29 18:56 UTC
Requires
- php: >=5.4
- moss/framework: >=1.2
- moss/locale: 2.*
- twig/extensions: 1.*
- twig/twig: 1.*
Requires (Dev)
- phpunit/phpunit: >=3.7
This package is not auto-updated.
Last update: 2022-02-01 12:41:55 UTC
README
MOSS Twig bridge
添加了 Twig 作为模板引擎并提供了额外的功能
资源 - 简化了对包资源的使用,为包资源/资产创建符号链接(如果不能,则复制它们,也可以强制执行此操作)。
<script src="{{ asset('/js/jquery.min.js') }}"></script>
将创建从 ./src/app/front/resource/js/jquery.min.js
到 ./web/resource/app/front/js/jquery.min.js
的符号链接。对其他文件也适用,只要它们放在包的资源目录中。
url - 方便的路由包装器 - {{ url('routeName', { here: "be", some: 'attributes' }) }}
。
翻译 - 翻译模块,合并了 Twigs i18n 扩展和更复杂的来自 Sf2 Translator
的复数化。
{% trans with {'%name%': 'Michal'} "Hello %name%" %} {% trans with {'%name%': 'Michal'} %}Hello %name%{% endtrans %} {% transchoice count with {'%name%': 'Michal'} %} {0} %name%, there are no apples|{1} %name%, there is one apple|]1,Inf] %name%, there are %count% apples {% endtranschoice %}
with {....}
是可选的,也可以省略
格式化 - 用于将值格式化为特定国家的格式
{{ $value|number }} - formats $value as number {{ $value|currency }} - formats $value as currency {{ $value|time }} - formats $value (which must be a \DateTime object) as time {{ $value|date }} - formats $value (\DateTime object) as date {{ $value|dateTime }} - formats $value (\DateTime object) as date time
当然,还包括正常的 Twig 扩展。
要使用它,只需将 bootstrap 中的默认 view
组件替换为
'view' => array( 'closure' => function (\Moss\Container\Container $container) { $options = array( 'debug' => true, 'auto_reload' => true, 'strict_variables' => false, 'cache' => '../compile/' ); $twig = new Twig_Environment(new Moss\Bridge\Loader\File(), $options); $twig->setExtensions( array( new Moss\Bridge\Extension\Resource(), new Moss\Bridge\Extension\Url($container->get('router')), new Moss\Bridge\Extension\Trans(), new Twig_Extensions_Extension_Text(), ) ); $view = new \Moss\Bridge\View\View($twig); $view ->set('request', $container->get('request')) ->set('config', $container->get('config')); return $view; } )
有关许可证详细信息,请参阅 LICENCE.md