Twig - Joomla Framework Language bridge

Installs: 18

Dependents: 0

Suggesters: 0

Stars: 5

Watchers: 3

Forks: 1

Open Issues: 1

v1.1.1 2014-04-26 15:29 UTC


Extensions provide filters to allow using of Joomla-Framework packages such as Language package in Twig templates.


Add "piotr-cz/twig-extensions-joomla": "~1.0" to require block in your composer.json and run composer install.

    "require": {
        "piotr-cz/twig-extensions-joomla": "~1.0"

Text extension

It's assumed that you will use Composer to handle autoloading.


Add the extension to the twig environment:

// Configure Twig
$loader = new \Twig_Loader_Filesystem(JPATH_TEMPLATES);
$twig = new \Twig_Environment($loader, $options = array());

// Register Extension
$twig->addExtension(new \TwigJoomla\Extension\TextExtension);

// Render Template
$template = $twig->loadTemplate('test.twig');
echo $template->render();


Extension is able to call any public method of Text (like Text::_(), Text::sprintf(), ...).

Accepted Parameters

  • $method Text method
  • Text arguments
The _ method (default)

Twig Template:

{{ "IMADEIT" | jtext }}

Language file:

IMADEIT     = "I made it!"


I made it!
The sprintf method

Twig template

{{ "HELLOW" | jtext('sprintf', 'World') }}

Language file

HELLOW      ="Hello %s!"


Hello World!

Date extension

This extension allows to use localised date output and instead of PHP intl extension uses Language package. Crucial functions imported from of JDate package.


$twig->addExtension(new \Twigoomla\Extension\DateExtension($config->get('timezone')));


Accepted Parameters

  • $format DateTime Format
  • $timezone String or DateTimeZone object (optional)

Twig template

{{ event.on | jdate('l, j. F Y') }}

Language File

SUNDAY      ="neděle"
JUNE        ="červen"


neděle, 1. červen 2014

Application setup

See Joomla-Framework/Language package for instructions on how to setup the Language package in your application.

Running tests

$ composer install
$ phpunit


This extensions are released under the MIT License, except Date extension which is released under GPL2