PHPackages                             derekderaps/twigshim - 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. derekderaps/twigshim

Abandoned → [https://www.drupal.org/project/twigshim](/?search=https%3A%2F%2Fwww.drupal.org%2Fproject%2Ftwigshim)Drupal-module[Templating &amp; Views](/categories/templating)

derekderaps/twigshim
====================

Shoehorns Twig template compiling into Drupal 7.

1.0.0-alpha1(9y ago)32.1k1[6 issues](https://github.com/kalamuna/twigshim/issues)MITPHP

Since Dec 7Pushed 8y ago24 watchersCompare

[ Source](https://github.com/kalamuna/twigshim)[ Packagist](https://packagist.org/packages/derekderaps/twigshim)[ RSS](/packages/derekderaps-twigshim/feed)WikiDiscussions 7.x-1.x Synced today

READMEChangelogDependencies (1)Versions (6)Used By (0)

Twigshim
========

[](#twigshim)

Shoehorns Twig template compiling into Drupal 7. Especially useful when you already have twig templates rendering your components in another system (e.g., an external styleguide) and don't want to re-implement everything in PHPTemplate.

Installation
------------

[](#installation)

### Download the Twig library

[](#download-the-twig-library)

This project depends on the Twig PHP library, which can be installed one of three ways:

1. [Composer Manager](https://www.drupal.org/project/composer_manager)\* (recommended)
2. [Composer](https://getcomposer.org/)
3. [Libraries API](https://www.drupal.org/project/libraries)\*

#### via Composer Manager

[](#via-composer-manager)

*This is the recommended installation method.* Install the [Composer Manager](https://www.drupal.org/project/composer_manager) module\* and follow its installation instructions to generate your `composer.json` and download your `vendor` dependencies. No extra work is required beyond the steps outlined in the Composer Manager project.

#### *or* via Composer

[](#or-via-composer)

Follow the installation instructions for the main [Composer](https://getcomposer.org/) project, then `cd` into this module's directory (probably `sites/all/modules/contrib/twigshim`) and run `composer install`.

#### *or* via Libraries API

[](#or-via-libraries-api)

Install the [Libraries API](https://www.drupal.org/project/libraries) module\* and download the [Twig library](http://twig.sensiolabs.org/) into your libraries directory (probably `sites/all/libraries`).

### Install the Twig Shim module

[](#install-the-twig-shim-module)

Follow the normal Drupal module installation procedure.\*

---

\**For instructions on installing Drupal modules, see the [Drupal.org documention](https://www.drupal.org/docs/7/extending-drupal-7/installing-contributed-modules-find-import-enable-configure).*

Usage
-----

[](#usage)

If your templates live anywhere other than in the `templates` subdirectory of your default theme, visit `/admin/conig/development/twigshim` and set the appropriate path. All your template references resolve relative to this path. Do not include leading or trailing slashes.

The main Twig Shim function is `twigshim_render()`. Call this with your template path (relative to the templates directory you just set) and an optional array of variables to be used in the template. Example:

```
/**
 * Implements hook_block_view().
 */
function mymodule_block_view($delta = '') {
  switch ($delta) {

    // Render the header block.
    case 'myblock':
      return twigshim_render('chrome/header.twig', array(
        'campaign'  => variable_get('mysite_current_campaign', 'Donate now!'),
        'hidePopup' => !user_is_anonymous(),
      ));
      break;
  }
}

```

When rendering an entity, use the helper function `twigshim_render_entity()` to automatically pull each of the entity's fields and properties into the variables array. It strips `field_` from the front of each key, facilitating the re-use of variables across both your style guide and implementation.

```
/**
 * Implements theme_HOOK() for paragraphs_item__button().
 */
function mytheme_paragraphs_item__button(&$vars) {

  // Get a wrapper for the button entity.
  $button = entity_metadata_wrapper('paragraphs_item', $vars['paragraphs_item']);

  // Set values for any fields that don't follow the standard format.
  $template_vars['href'] = $button->field_href->url->value();

  return twigshim_render_entity('paragraphs_item', $button, 'button/button.twig', $template_vars);
}

```

Note that it is the caller's responsibility to properly sanitize all variables before passing into Twig Shim. See the Drupal.org documentation on [writing secure code](http://drupal.org/writing-secure-code) and the [sanitisation functions](https://api.drupal.org/api/drupal/includes!common.inc/group/sanitization/7.x).

###  Health Score

24

—

LowBetter than 31% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 73.7% 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

Unknown

Total

1

Last Release

3464d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/56cdb1522b7917944ca67251264364f3a123b1ee3011f555d3b54172fff9f952?d=identicon)[derekderaps](/maintainers/derekderaps)

---

Top Contributors

[![RobLoach](https://avatars.githubusercontent.com/u/25086?v=4)](https://github.com/RobLoach "RobLoach (14 commits)")[![gremy](https://avatars.githubusercontent.com/u/1007285?v=4)](https://github.com/gremy "gremy (3 commits)")[![soniktrooth](https://avatars.githubusercontent.com/u/597617?v=4)](https://github.com/soniktrooth "soniktrooth (2 commits)")

### Embed Badge

![Health badge](/badges/derekderaps-twigshim/health.svg)

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

###  Alternatives

[craftcms/cms

Craft CMS

3.6k3.6M2.9k](/packages/craftcms-cms)

PHPackages © 2026

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