piotr-cz / twig-extensions-joomla
Twig - Joomla Framework Language bridge
Requires
- php: >=5.3.0
- joomla/language: ~1.1
- twig/twig: ~1.0
This package is not auto-updated.
Last update: 2024-12-21 17:53:43 UTC
README
Extensions provide filters to allow using of Joomla-Framework packages such as Language package in Twig templates.
Installation
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.
Setup
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();
Usage
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!"
Result:
I made it!
The sprintf
method
Twig template
{{ "HELLOW" | jtext('sprintf', 'World') }}
Language file
HELLOW ="Hello %s!"
Result
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.
Setup
$twig->addExtension(new \Twigoomla\Extension\DateExtension($config->get('timezone')));
Usage
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"
Result
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
Licence
This extensions are released under the MIT License, except Date extension which is released under GPL2