Giter Club home page Giter Club logo

think-twig's Introduction

think-twig

tp6 twig模板

#安装方式

composer require rain-sjh/think-twig

#缓存配置

'tpl_cache'    => true  当为 true 时启用缓存, 当为 false 时 关闭缓存.

安装完成后请在config配置文件view.php进行一下配置

return [
    // 模板引擎类型使用 Think
    'type'          => 'Twig',
    // 默认模板渲染规则 1 解析为小写+下划线 2 全部转换小写 3 保持操作方法
    'auto_rule'     => 1,
    // 模板目录名
    'view_dir_name' => 'view',
    // 模板后缀
    'view_suffix'   => 'twig',
    // 模板文件名分隔符
    'view_depr'     => DIRECTORY_SEPARATOR,
    // 模板引擎普通标签开始标记
    'tpl_begin'     => '{{',
    // 模板引擎普通标签结束标记
    'tpl_end'       => '}}',
    // 标签库标签开始标记
    'taglib_begin'  => '{%',
    // 标签库标签结束标记
    'taglib_end'    => '%}',
    // 是否开启缓存
    'tpl_cache'    => true
];

如需拓展twig模板函数,请在extend下创建 TwigExpand.php 并实现接口

use Twig\Extension\AbstractExtension;
use Twig\NodeVisitor\NodeVisitorInterface;
use Twig\TokenParser\TokenParserInterface;
use Twig\TwigFunction;
use Twig\TwigFilter;

class TwigExpand extends AbstractExtension
 {
 	/**
 	 * 过滤器 拓展.
 	 * @return TwigFilter[]
 	 */
 	public function getFilters()
 	{
 		return [
 		];
 	}
 
 	/**
 	 * 函数 拓展.
 	 * @return TwigFunction[]
 	 */
 	public function getFunctions()
 	{
 		return [
 		];
 	}
 
 	/**
 	 * Token的解析器 拓展.
 	 * @return array|TokenParserInterface[]
 	 */
 	public function getTokenParsers()
 	{
 		return [];
 	}
 
 	/**
 	 * 节点访问器 拓展.
 	 * @return array|NodeVisitorInterface[]
 	 */
 	public function getNodeVisitors()
 	{
 		return [];
 	}
 
 	/**
 	 * 测试 拓展.
 	 *
 	 * @return Twig_Test[]
 	 */
 	public function getTests()
 	{
 		return [];
 	}
 
 	/**
 	 * 运算符 拓展.
 	 * @return array<array> First array of unary operators, second array of binary operators
 	 */
 	public function getOperators()
 	{
 		return [];
 	}
 }

think-twig's People

Contributors

raind-sjh avatar rain-sjh avatar fight3long3 avatar

Stargazers

Xue qingyan avatar 1ce bear avatar  avatar  avatar tanzhenxing avatar

Watchers

 avatar  avatar  avatar

Forkers

kp16347 coolf

think-twig's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.