PHPackages                             sygytyr/yii2-mustache - 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. sygytyr/yii2-mustache

ActiveYii2-extension

sygytyr/yii2-mustache
=====================

Mustache templating for the Yii Framework.

051PHP

Since Jun 13Pushed 1y ago1 watchersCompare

[ Source](https://github.com/Sygytyr/yii2-mustache)[ Packagist](https://packagist.org/packages/sygytyr/yii2-mustache)[ RSS](/packages/sygytyr-yii2-mustache/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Mustache for Yii
================

[](#mustache-for-yii)

[![Runtime](https://camo.githubusercontent.com/fd9db884e729cadb2bf5ef13ab42977ac67a7d37be88a34dfd9cde1d7b28e26f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344372e312d627269676874677265656e2e737667)](https://camo.githubusercontent.com/fd9db884e729cadb2bf5ef13ab42977ac67a7d37be88a34dfd9cde1d7b28e26f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344372e312d627269676874677265656e2e737667) [![Release](https://camo.githubusercontent.com/5ea17868bc90aba3faca2dda120b704a82b39d9e214b5f33b020e2b063023277/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f636564782f796969322d6d757374616368652e737667)](https://camo.githubusercontent.com/5ea17868bc90aba3faca2dda120b704a82b39d9e214b5f33b020e2b063023277/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f636564782f796969322d6d757374616368652e737667) [![License](https://camo.githubusercontent.com/07f36d1994f27382e94bc5338c1731282ac16de72c92e5563c9f58478d0da235/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f636564782f796969322d6d757374616368652e737667)](https://camo.githubusercontent.com/07f36d1994f27382e94bc5338c1731282ac16de72c92e5563c9f58478d0da235/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f636564782f796969322d6d757374616368652e737667) [![Downloads](https://camo.githubusercontent.com/96faad101aa8011ac264e48efa32ddffa7e8b0fcf320e6ffbabbaae5b34c7f4a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f636564782f796969322d6d757374616368652e737667)](https://camo.githubusercontent.com/96faad101aa8011ac264e48efa32ddffa7e8b0fcf320e6ffbabbaae5b34c7f4a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f636564782f796969322d6d757374616368652e737667) [![Coverage](https://camo.githubusercontent.com/43ae88142ab3c6f93585cd5fb2732af28ef71ede6cd84d4600eac97c422793c7/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f636564782f796969322d6d757374616368652f62616467652e737667)](https://camo.githubusercontent.com/43ae88142ab3c6f93585cd5fb2732af28ef71ede6cd84d4600eac97c422793c7/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f636564782f796969322d6d757374616368652f62616467652e737667) [![Build](https://camo.githubusercontent.com/a9fd8185a11d4bfbdee516d898114bdba9f7f9cc743b246e39eed0cf9ef2cfa4/68747470733a2f2f7472617669732d63692e6f72672f636564782f796969322d6d757374616368652e737667)](https://camo.githubusercontent.com/a9fd8185a11d4bfbdee516d898114bdba9f7f9cc743b246e39eed0cf9ef2cfa4/68747470733a2f2f7472617669732d63692e6f72672f636564782f796969322d6d757374616368652e737667)

[Mustache](http://mustache.github.io) templating for [Yii](http://www.yiiframework.com), high-performance [PHP](https://secure.php.net) framework.

This package provides a view renderer, the `yii\mustache\ViewRenderer` class. This renderer allows to use [Mustache syntax](https://mustache.github.io/mustache.5.html) in view templates.

Requirements
------------

[](#requirements)

The latest [PHP](https://secure.php.net) and [Composer](https://getcomposer.org) versions. If you plan to play with the sources, you will also need the latest [Phing](https://www.phing.info) version.

Installing via [Composer](https://getcomposer.org)
--------------------------------------------------

[](#installing-via-composer)

From a command prompt, run:

```
$ composer global require fxp/composer-asset-plugin
$ composer require sygytyr/yii2-mustache
```

Configuring application
-----------------------

[](#configuring-application)

In order to start using Mustache you need to configure the `view` application component, like the following:

```
use yii\mustache\{ViewRenderer};
use yii\web\{View};

return [
  'components' => [
    'view' => [
      'class' => View::class,
      'renderers' => [
        'mustache' => ViewRenderer::class
      ]
    ]
  ]
];
```

After it's done you can create templates in files that have the `.mustache` extension (or use another file extension but configure the component accordingly). Unlike standard view files, when using Mustache you must include the extension in your `$this->render()` controller call:

```
return $this->render('template.mustache', [ 'model' => 'The view model' ]);
```

Template Syntax
---------------

[](#template-syntax)

The best resource to learn Mustache basics is its official documentation you can find at [mustache.github.io](http://mustache.github.io). Additionally there are Yii-specific syntax extensions described below.

### Variables

[](#variables)

Within Mustache templates the following variables are always defined:

- `app`: the [`Yii::$app`](http://www.yiiframework.com/doc-2.0/yii-baseyii.html#$app-detail) instance.
- `this`: the current [`View`](http://www.yiiframework.com/doc-2.0/yii-base-view.html) object.
- `yii.debug`: the `YII_DEBUG` constant.
- `yii.devEnv`: the `YII_ENV_DEV` constant.
- `yii.prodEnv`: the `YII_ENV_PROD` constant.
- `yii.testEnv`: the `YII_ENV_TEST` constant.

### Lambdas

[](#lambdas)

- `format`: provides a set of commonly used data formatting methods.
- `html`: provides a set of methods for generating commonly used HTML tags.
- `i18n`: provides features related with internationalization (I18N) and localization (L10N).
- `url`: provides a set of methods for managing URLs.

### Partials

[](#partials)

There are two ways of referencing partials:

```
{{> post }}
{{> @app/views/layouts/2columns }}

```

In the first case the view will be searched relatively to the current view path. For `post.mustache`that means these will be searched in the same directory as the currently rendered template.

In the second case we're using path aliases. All the Yii aliases such as `@app` are available by default.

See also
--------

[](#see-also)

- [API reference](https://cedx.github.io/yii2-mustache)
- [Code coverage](https://coveralls.io/github/cedx/yii2-mustache)
- [Continuous integration](https://travis-ci.org/cedx/yii2-mustache)

License
-------

[](#license)

[Mustache for Yii](https://github.com/cedx/yii2-mustache) is distributed under the MIT License.

###  Health Score

15

—

LowBetter than 3% of packages

Maintenance27

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity18

Early-stage or recently created project

 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.

### Community

Maintainers

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

---

Top Contributors

[![Sygytyr](https://avatars.githubusercontent.com/u/20863763?v=4)](https://github.com/Sygytyr "Sygytyr (2 commits)")

### Embed Badge

![Health badge](/badges/sygytyr-yii2-mustache/health.svg)

```
[![Health](https://phpackages.com/badges/sygytyr-yii2-mustache/health.svg)](https://phpackages.com/packages/sygytyr-yii2-mustache)
```

PHPackages © 2026

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