allmarkedup/twig-extensions

A few handy extensions for Twig.

v0.2 2014-10-30 10:33 UTC

This package is not auto-updated.

Last update: 2024-12-17 04:29:14 UTC


README

A few handy extensions for Twig.

Included extensions:

Installation and use

Using composer:

$ composer require allmarkedup/twig-extensions

Then load the required extension(s) into the Twig environment when setting it up as per the instructions in the Twig docs. For example, to use the Markdown extension, you would use something like this:

<?php
use Amu\Twig\TwigMarkdownExtension as MarkdownExtension;
//...
$twig = new Twig_Environment($loader, $options);
$twig->addExtension(new MarkdownExtension());

Included extensions

Markdown Extension

The Markdown extension uses Parsedown under the hood to allow for easy Markdown -> HTML conversion in your templates.

To install:

<?php
$twig->addExtension(new Amu\Twig\TwigMarkdownExtension());

Use it in your templates as a filter:

{{ 'This is a **string**' | markdown }}

Or use it as a tag:

{% markdown %}
_This sentence is emphasised_
> And this is a quote.
{% endmarkdown %}

Running tests

Tests can be run using PHP Unit:

$ vendor/bin/phpunit 

The project also includes a Grunt watch task to run the PHP Unit tests when files are updated which you can use for your convenience.