PHPackages                             snowair/think-twig - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. snowair/think-twig

ActiveLibrary[Templating &amp; Views](/categories/templating)

snowair/think-twig
==================

ThinkPHP3.2 twig模板引擎

1751PHP

Since Sep 15Pushed 10y ago3 watchersCompare

[ Source](https://github.com/snowair/think-twig)[ Packagist](https://packagist.org/packages/snowair/think-twig)[ RSS](/packages/snowair-think-twig/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

介绍
==

[](#介绍)

ThinkPHP3.2 Twig模板引擎

安装
--

[](#安装)

[composer中文文档](http://www.kancloud.cn/thinkphp/composer)

```
composer require snowair/think-twig:dev-master

```

引擎配置
----

[](#引擎配置)

```
/* Twig模板引擎设置 */
'TMPL_ENGINE_TYPE'      =>  'Twig',      // 设置为Twig启用twig引擎
'TMPL_TEMPLATE_SUFFIX'  =>  '.html',     // 设置模板后缀, 可自由设置
'TMPL_FILE_DEPR'        =>  '/',         // 模板文件CONTROLLER_NAME与ACTION_NAME之间的分割符

```

做完上面的配置, twig就生效了:

```

{{var}}

```

```
// 控制器aciton
    ...
    $this->assign('var','hello world');
    $this->display(); // or `echo $this->fetch();`

```

- 注意: Twig不支持控制器的 show 方法.

跳转页面配置
------

[](#跳转页面配置)

**无论引擎配置如何, Controller的error/success方法的模板始终采用think引擎渲染.**

如果您确实需要使用twig引擎自定义这两种页面的模板, 只需要使用 `TMPL_ACTION_ERROR`和`TMPL_ACTION_SUCESS`配置指定模板文件的位置,并将模板文件的后缀名改为`twig`即可.

```
'TMPL_ACTION_ERROR'     =>  THINK_PATH.'Tpl/dispatch_jump.twig', // 使用twig渲染错误页面
'TMPL_ACTION_SUCCESS'   =>  THINK_PATH.'Tpl/dispatch_jump.twig', // 使用twig渲染成功页面

```

- 注:异常页面模板, 不支持任何模板引擎.

配置Twig
------

[](#配置twig)

如果需要, 任何时候都可以配置Twig, 推荐在 `app_begin` 阶段配置

示例:

```
$twig = \Think\Template\Driver\Twig::getInstance();
$escaper = new \Twig_Extension_Escaper('html');
$twig->addExtension($escaper);

```

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/0eb057945348a8d33b62872e67cbf4dd9d589db4330815c9b246ab5a51113720?d=identicon)[snowair](/maintainers/snowair)

### Embed Badge

![Health badge](/badges/snowair-think-twig/health.svg)

```
[![Health](https://phpackages.com/badges/snowair-think-twig/health.svg)](https://phpackages.com/packages/snowair-think-twig)
```

###  Alternatives

[mustache/mustache

A Mustache implementation in PHP.

3.3k44.6M291](/packages/mustache-mustache)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)[whitecube/nova-flexible-content

Flexible Content &amp; Repeater Fields for Laravel Nova.

8053.0M25](/packages/whitecube-nova-flexible-content)[mopa/bootstrap-bundle

Easy integration of twitters bootstrap into symfony2

7042.9M33](/packages/mopa-bootstrap-bundle)[limenius/react-bundle

Client and Server-side react rendering in a Symfony Bundle

3871.2M](/packages/limenius-react-bundle)[symfony/ux-icons

Renders local and remote SVG icons in your Twig templates.

545.8M69](/packages/symfony-ux-icons)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
