piotr-cz/twig-extensions-joomla
Composer 安装命令:
composer require piotr-cz/twig-extensions-joomla
包简介
Twig - Joomla Framework Language bridge
关键字:
README 文档
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
$methodText 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
$formatDateTime Format$timezoneString 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
统计信息
- 总下载量: 36
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 6
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2014-03-17