Caffeina Core 视图使用的 Twig 服务

安装数量: 5,285

依赖项: 1

建议者: 0

安全性: 0

星标: 0

关注者: 4

分支: 0

公开问题: 0

类型:core-bundle

1.2.0 2016-03-31 15:11 UTC

This package is auto-updated.

Last update: 2024-09-16 20:29:27 UTC


README

Scrutinizer Code Quality Build Status Total Downloads Latest Stable Version Latest Unstable Version License

TwigCore 视图创建的桥梁。

安装

通过 composer 安装

$ composer require caffeina-core/twig -o

Twig

Twig 文档: http://twig.sensiolabs.org/documentation

Twig Core\View 扩展

添加 Twig 过滤器

View::addFilter('rot13',function($text){
  return str_rot13($text);
});
<li>test = {{ test|rot13 }}</li>

输出

<li>test = grfg</li>

添加全局常量

View::addGlobals([
  'BASE_URL'     => '/site/',
  'ASSETS_URL'   => '/site/assets/',
]);
<script src="{{ ASSETS_URL }}js/main.js"></script>

添加 Twig 函数

View::addFunction('myFunction',function($a,$b,$c){
  return $a + $b + $c;
});
Value = <b>{{ myFunction(1,2,3) }}</b>

输出

Value = <b>6</b>