本文主要是介绍PHP Template Engine:Twig 语法汇总,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
1.Twig 简介
Twig作为PHP模板引擎,具有如下特点:
- Fast: Twig compiles templates down to plain optimized PHP code. The overhead compared to regular PHP code was reduced to the very minimum.
- Secure: Twig has a sandbox mode to evaluate untrusted template code. This allows Twig to be used as a template language for applications where users may modify the template design.
- Flexible: Twig is powered by a flexible lexer and parser. This allows the developer to define its own custom tags and filters, and create its own DSL.
2.语法Syntax
参考官方文档:Twig for Template Designers
2.1 常用IDE twig扩展
- Textmate via the Twig bundle
- Vim via the Jinja syntax plugin or the vim-twig plugin
- Netbeans via the Twig syntax plugin (until 7.1, native as of 7.2)
- PhpStorm (native as of 2.1)
- Eclipse via the Twig plugin
- Sublime Text via the Twig bundle
- GtkSourceView via the Twig language definition (used by gedit and other projects)
- Coda and SubEthaEdit via the Twig syntax mode
- Coda 2 via the other Twig syntax mode
- Komodo and Komodo Edit via the Twig highlight/syntax check mode
- Notepad++ via the Notepad++ Twig Highlighter
- Emacs via web-mode.el
2.2 variables 变量
例子
1. {{ foo.bar }}
2. {{ foo['
这篇关于PHP Template Engine:Twig 语法汇总的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!