PHPackages                             frozzare/digster - 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. frozzare/digster

ActiveWordpress-muplugin[Templating &amp; Views](/categories/templating)

frozzare/digster
================

Twig templates for WordPress

v1.8.1(9y ago)107.1k1MITPHPPHP &gt;=5.4.7

Since May 18Pushed 7y ago2 watchersCompare

[ Source](https://github.com/wpup/digster)[ Packagist](https://packagist.org/packages/frozzare/digster)[ Docs](https://github.com/frozzare/wp-digster)[ RSS](/packages/frozzare-digster/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (8)Versions (26)Used By (0)

Digster
=======

[](#digster)

[![Build Status](https://camo.githubusercontent.com/4d27e0978418641a4b5cc1c29254e4fa165b317ef6f559acb38f07df5d80d27d/68747470733a2f2f7472617669732d63692e6f72672f777075702f646967737465722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/wpup/digster)[![No Maintenance Intended](https://camo.githubusercontent.com/d904056147052e22d8e1c7f46bb50293ed2aeb4c43ead9a2d0cf7a48b46d0562/687474703a2f2f756e6d61696e7461696e65642e746563682f62616467652e737667)](http://unmaintained.tech/)

> Twig templates for WordPress

Digster it's a WordPress plugin that allows you to render Twig views with a few Twig [filters](#twig-filters), [functions](#twig-functions) and [globals](#twig-globals).

It's easy to register your own [extensions](#register-extension) or [composers](#register-composer).

Install
-------

[](#install)

```
composer require frozzare/digster

```

Example
-------

[](#example)

Example of `page.php`

```
/**
 * Render page view.
 */
echo view( 'page' );
```

Example of `page.twig`

```
{% include "partials/header.twig" %}

				{{ post.post_title }}

				{{ post.post_content | wpautop | raw }}

{% include "partials/footer.twig" %}
```

Configuration
-------------

[](#configuration)

Digster has a few WordPress filters, one is the config filter. Debug is turn on by default if `WP_ENV` equals `development`

```
add_filter( 'digster/config', function ( $config ) {
  return $config;
} );
```

#### Locations

[](#locations)

A array with the locations of the views. By default the `get_templates_directory() . '/views'` is registered.

```
add_filter( 'digster/config', function ( $config ) {
  $config['locations'] = 'path/to/locations';
  return $config;
} );
```

#### Twig environment options

[](#twig-environment-options)

Read about the options on the [Twig site](http://twig.sensiolabs.org/doc/api.html#environment-options)

`auto_reload` example

```
add_filter( 'digster/config', function ( $config ) {
  $config['auto_reload'] = true;
  return $config;
} );
```

API functions
-------------

[](#api-functions)

All functions that has `digster_` prefix can also be called as a static method on `\Frozzare\Digster\Digster` class. Just replace `digster_` with `Digster::`, make sure that you have in your code `use Frozzare\Digster\Digster`

##### Fetch view

[](#fetch-view)

Fetch the view in to a string.

```
$view = digster_fetch( 'page' [, $data = [] ] );
```

#### Get the view instance

[](#get-the-view-instance)

Every view in digster is a instance of the view class and this can be accessed.

```
$view = digster_view( 'page', [, $data = [] ] );

// or (only if `view` function don't exists.)
$view = view( 'page', [, $data = [] ] );

echo $view;
```

#### Nested views

[](#nested-views)

`digster_view` or `view` will return the view instance so you can use the `nest` method.

```
echo view( 'user.profile' )
  ->nest( 'picture', 'user.profile.picture', [
    'url' => 'http://site.com/user/1/profile.png'
  ] );
```

```
{# views/user/profile.twig #}
{{ picture }}
```

```
{# views/user/profile/picture.twig #}

```

You can do the same with `digster_render` and `digster_fetch`

```
digster_render( 'user.profile', [
  'picture' => digster_fetch( 'user.profile.picture', [
      'url' => 'http://site.com/user/1/profile.png'
  ] )
] );
```

#### Register composer

[](#register-composer)

With Digster you can register composer with wildcard template or a specified template.

This example is for `post` object, but Digster already have this global variable loaded.

```
// '*', 'page' or 'page.twig'
digster_composer( 'page', function ( $vars ) {
  $vars['post'] = is_numeric( $vars['post'] ) ?  get_page( $vars['post'] ) : $vars['post'];
  return $vars;
});

// Only need to get the post ID
digster_render( 'page', [
  'post' => get_the_ID()
] );
```

You can also create a composer class that you can add with `digster_composer`. The only method that is required on a composer class is `compose` that takes a view argument.

```
class Profile_Composer {

  public function compose( $view ) {
    $view->with( 'job', 'developer' );
  }

}

digster_composer( 'user.profile', 'Profile_Composer' );
```

#### Register custom filters

[](#register-custom-filters)

Since `1.7.1`

```
add_filter( 'digster/filters', function ( $filters ) {
  return array_merge( $filters, [
    'hello' => function ( $text ) {
      return 'hello';
    }
  ] )
} );
```

#### Register custom functions

[](#register-custom-functions)

Since `1.7.1`

```
add_filter( 'digster/functions', function ( $functions ) {
  return array_merge( $functions, [
    'uniqid' => 'uniqid'
  ] )
} );
```

#### Register custom globals

[](#register-custom-globals)

Since `1.7.1`

```
add_filter( 'digster/globals', function ( $globals ) {
  return array_merge( $globals, [
    'num' => 1
  ] )
} );
```

#### Register extension

[](#register-extension)

Register [Twig extension](http://twig.sensiolabs.org/doc/advanced.html) classes with Digster.

```
digster_register_extensions( new My_First_Twig_Extension() );

// or

digster_register_extensions( [
	new My_First_Twig_Extension(),
	new My_Second_Twig_Extension()
] );
```

#### Render a view

[](#render-a-view)

Render a view

```
digster_render( 'page' [, $data = []] );
```

#### Share data between views

[](#share-data-between-views)

You can either use `digster_composer` with `*` (wildcard) to share data between views or use `digster_share`. All shared that can be overwrite.

```
digster_share( 'site_name', 'Example' );
```

Twig filters
------------

[](#twig-filters)

#### apply\_filters

[](#apply_filters)

Apply filters to Twig output.

```
{{ '@frozzare' | apply_filters('twitter_link') }}
```

#### Excerpt

[](#excerpt)

Get the post summary

```
{{ post.post_content | excerpt }}
```

#### Shortcodes

[](#shortcodes)

Run WordPress shortcodes on the text

```
{{ post.post_content | shortcodes | raw }}
```

#### wpautop

[](#wpautop)

Append p tags to the text

```
{{ post.post_content | wpautop | raw }}
```

Twig functions
--------------

[](#twig-functions)

Since `1.7.1` you can call `esc_html__`, `esc_html_e`, `esc_attr__`, `esc_attr_e`, `esc_js`, `esc_textarea`, `esc_url` and `esc_url_raw` with the same arguments as you should use in WordPress.

#### Call `__`

[](#call-__)

The same argument as WordPress's [\_\_](https://codex.wordpress.org/Function_Reference/_2).

Digster has full support for Twig i18n, [read more about it](#twig-i18n).

```
{{ __( 'Hello World!', 'your_textdomain' ) }}
```

#### Call `_n`

[](#call-_n)

The same argument as WordPress's [\_n](https://codex.wordpress.org/Function_Reference/_n).

Digster has full support for Twig i18n, [read more about it](#twig-i18n).

```
{{ _n('%s star', '%s stars', rating, 'your_textdomain') | format(rating) }}
```

#### Call action

[](#call-action)

You can send more arguments to `do action`

```
{% do action('my_action') %}
```

#### Call apply\_filters

[](#call-apply_filters)

Takes the same arguments as `apply_filters`

```
{{ apply_filters() }}
```

#### Call body\_class

[](#call-body_class)

```

```

#### Call language\_attributes

[](#call-language_attributes)

```

```

#### Call random function

[](#call-random-function)

You can send in more arguments to `fn`

```

```

#### Call wp\_footer

[](#call-wp_footer)

```
{{ wp_footer() }}
```

#### Call wp\_head

[](#call-wp_head)

```
{{ wp_head() }}
```

#### Call wp\_title

[](#call-wp_title)

Takes the same arguments as `wp_title`

```
{{ wp_title() }}
```

Twig globals
------------

[](#twig-globals)

#### post

[](#post)

`post` is global when `get_the_ID()` returns a id.

```
{{ post.post_title }}
```

Twig i18n
---------

[](#twig-i18n)

Digster has full support for Twig [i18n](http://twig.sensiolabs.org/doc/extensions/i18n.html) extensions. You don't have to do anything to enable it, just use it! It will load the theme text domain automatic. Don't forget to add it to your `style.css`.

Using [Poedit](https://poedit.net)? You should look at [Twig Gettext Extractor](https://github.com/umpirsky/Twig-Gettext-Extractor)! Digster will install Twig Gettext Extractor so you don't have to do it!

```
{% trans "Hello World!" %}

{% trans string_var %}

{% trans %}
    Hello World!
{% endtrans %}
```

Cache
-----

[](#cache)

Look at [Twig cache extension](https://github.com/asm89/twig-cache-extension) (Digster installs the package so you don't have to install it). Digster has a build in cache provider that uses the [WordPress Object cache](http://codex.wordpress.org/Class_Reference/WP_Object_Cache).

```
use Frozzare\Digster\Cache\WordPress_Cache_Adapter;
use Asm89\Twig\CacheExtension\CacheStrategy\LifetimeCacheStrategy;
use Asm89\Twig\CacheExtension\Extension as CacheExtension;

$cache_provider  = new WordPress_Cache_Adapter();
$cache_strategy  = new LifetimeCacheStrategy($cache_provider);
$cache_extension = new CacheExtension($cache_strategy);

digster_register_extensions( $cache_extension );
```

Coding style
------------

[](#coding-style)

You can check if your contribution passes the styleguide by installing [PHP CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer) and running the following in your project directory:

```
vendor/bin/phpcs -s --extensions=php --standard=phpcs.xml src/

```

License
-------

[](#license)

MIT © [Fredrik Forsmo](https://github.com/frozzare)

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity25

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity68

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 ~24 days

Total

22

Last Release

3511d ago

### Community

Maintainers

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

---

Top Contributors

[![frozzare](https://avatars.githubusercontent.com/u/14610?v=4)](https://github.com/frozzare "frozzare (240 commits)")

---

Tags

twigwordpresswordpresstwiglibray

### Embed Badge

![Health badge](/badges/frozzare-digster/health.svg)

```
[![Health](https://phpackages.com/badges/frozzare-digster/health.svg)](https://phpackages.com/packages/frozzare-digster)
```

###  Alternatives

[timber/timber

Create WordPress themes with beautiful OOP code and the Twig Template Engine

5.7k3.4M111](/packages/timber-timber)

PHPackages © 2026

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