dotblue / nette-templating
Localizable templates with smooth setup in Nette Framework
Installs: 3 046
Dependents: 0
Suggesters: 0
Security: 0
Stars: 5
Watchers: 5
Forks: 0
Open Issues: 0
Requires
- php: >=5.4
- nette/nette: >=2.1.0,<2.3.0
This package is not auto-updated.
Last update: 2024-10-26 15:46:32 UTC
README
Requirements
- PHP 5.4+
- nette/nette >= 2.1
Installation
- Copy source codes from Github or using Composer:
$ composer require dotblue/nette-templating@~1.0
- Register as Configurator's extension:
extensions:
templateHelpers: DotBlue\Templating\Helpers\Extension
- Register your helpers:
templateHelpers:
- ShoutHelper
How should MyHelper
look?
use DotBlue\Templating\Helpers; class ShoutHelper implements Helpers\IHelper { public function getName() { return 'shout'; } public function execute($value, Helpers\Options $options) { return $value . '!'; } }
All arguments are wrapped in Options
object.
public function execute($value, Helpers\Options $options) { $mark = $options->first('!'); return $value . $mark; }
{var $text = 'Hi'} {$text|shout:'!!!'} {* print "Hi!!!" *}
Localization
You can use new macro {locale $language /}
in your templates (best place is your layout). Provided $language
variable is then available in helper via Options
object:
$language = $options->getLocale();
$language
can be anything you wish. You can also place {locale}
macro in template multiple times, for example to print amount of money in all localized versions (using hypothetical currency
helper):
{foreach $languages as $language} {locale $language} {$money|currency} {/locale} {/foreach}