PHPackages                             ke/thinkphp-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. ke/thinkphp-twig

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

ke/thinkphp-twig
================

3.0.1(5y ago)036PHP

Since Jan 18Pushed 5y ago1 watchersCompare

[ Source](https://github.com/wdaglb/thinkphp-twig)[ Packagist](https://packagist.org/packages/ke/thinkphp-twig)[ RSS](/packages/ke-thinkphp-twig/feed)WikiDiscussions master Synced 5d ago

READMEChangelog (6)Dependencies (2)Versions (8)Used By (0)

**安装**

```
composer require ke/thinkphp-twig

```

**使用**

> 需要在template.php里把type节点修改为\\ke\\Twig，如：

```
'type'         => \ke\Twig::class,
'view_suffix'  => 'twig',

```

*PS:官方的tpl\_begin,tpl\_end,taglib\_begin,taglib\_end配置节点是无效的*

**注册全局变量**

```
    'global_vars'=>[
        '__STATIC__'=>'/static'
    ]

```

**注册拓展库**

> twig不支持直接使用php的函数,但是可以经过拓展定义使用

```
// 在template.php的extension里传入类名，如（必须是数组）：
    'extension'=>[
        \taglib\Lib::class
    ]

```

> 生成url

```
{{ url('index') }}

```

> 使用Request对象

```
// 读取$_GET['page']
{{ Request.get.page }}

```

> 使用Config对象

```
// 判断当前是否调试
{{ Config.app_debug }}

```

> if判断

```
{% if condition %}
真
{% else %}
假
{% endif %}

// 判断变量是否定义
{% if item is defined %}
变量已定义
{% endif %}

// 判断变量是否为空
{% if item is null %}
变量为空
{% endif %}

```

> 循环一个数组

```
{% for item in array %}
    {{ item.name }}
{% endfor %}

{% for index, item in array %}
    {{ index }}:
    {{ item.name }}
{% endfor %}

{% for item in array %}
    * {{ item.name }}
{% else %}
    No array have been found.
{% endfor %}

```

> 指定次数循环

```
{% for num in 1..20 %}
    {{ num }}
{% endfor %}

```

> 注释

```
{# 注释内容 #}

```

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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.

###  Release Activity

Cadence

Every ~116 days

Recently: every ~160 days

Total

7

Last Release

1979d ago

Major Versions

1.0.2 → 3.0.02020-12-11

1.0.3 → 3.0.x-dev2020-12-13

### Community

Maintainers

![](https://www.gravatar.com/avatar/e75ee598a8771c24bfee4989062d3efcd22c0f6886d1771c73e0b373d010c432?d=identicon)[wdaglb](/maintainers/wdaglb)

---

Top Contributors

[![wdaglb](https://avatars.githubusercontent.com/u/19158680?v=4)](https://github.com/wdaglb "wdaglb (23 commits)")

---

Tags

twigthinkphp

### Embed Badge

![Health badge](/badges/ke-thinkphp-twig/health.svg)

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

###  Alternatives

[twig/extra-bundle

A Symfony bundle for extra Twig extensions

91292.0M315](/packages/twig-extra-bundle)[twig/intl-extra

A Twig extension for Intl

36663.2M221](/packages/twig-intl-extra)[rcrowe/twigbridge

Adds the power of Twig to Laravel

9105.9M50](/packages/rcrowe-twigbridge)[twig/string-extra

A Twig extension for Symfony String

21946.0M133](/packages/twig-string-extra)[twig/cssinliner-extra

A Twig extension to allow inlining CSS

23018.5M55](/packages/twig-cssinliner-extra)[symfony/ux-twig-component

Twig components for Symfony

21814.8M162](/packages/symfony-ux-twig-component)

PHPackages © 2026

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