Download the PHP package derekderaps/twigshim without Composer
On this page you can find all versions of the php package derekderaps/twigshim. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download derekderaps/twigshim
More information about derekderaps/twigshim
Files in derekderaps/twigshim
Package twigshim
Short Description Shoehorns Twig template compiling into Drupal 7.
License MIT
Informations about the package 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
Download the Twig library
This project depends on the Twig PHP library, which can be installed one of three ways:
- Composer Manager* (recommended)
- Composer
- Libraries API*
via Composer Manager
This is the recommended installation method. Install the 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
Follow the installation instructions for the main
Composer project, then cd
into this module's
directory (probably sites/all/modules/contrib/twigshim
) and run composer install
.
or via Libraries API
Install the Libraries API module*
and download the Twig library into your libraries
directory (probably sites/all/libraries
).
Install the Twig Shim module
Follow the normal Drupal module installation procedure.*
*For instructions on installing Drupal modules, see the Drupal.org documention.
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:
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.
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 and the sanitisation functions.