nedryse/latte-template-macroset
最新稳定版本:v1.0.0
Composer 安装命令:
composer require nedryse/latte-template-macroset
包简介
Placeholder replacement Latte macro provides simple way to put the content of variables into the right places.
README 文档
README
#nedryse/latte-template-macroset (cc)# Pavel Železný (2bfree), 2014 (pavelzelezny.cz)
Requirements
Nette Framework 2.2.0 or higher
Documentation
Placeholder replacement Latte macro provides simple way to put the content of variables into the right places.
Macroset provides {template ...} macro and overwrites {_ ...} macro with same mechanism.
First argument of these macros can contain any number of {:placeholders} in the string that will be replaced by the same named variables.
Replacement variables are taken from the template like $template->placeholder, are overwritten by local variable like {var $placeholder} and are overwritten by arguments of macros like {template ..., 'placeholder' => 'replacement', ...} or {template ..., array('placeholder' => 'replacement', ...)}.
Replacement variables can contain {:nested_placeholders}, that will be replaced also.
The functionality of {_ ...} macro is maintained. All arguments of the macro are sended to the translator unchanged. Result of the translator will be used as template that can contain {:placeholders}. With this functionality you can change the possition of given arguments to provide propper number of translator plurals as the first argument of the macro.
Instalation
Prefered way to intall is by Composer
composer require nedryse/latte-template-macroset:~1.0.0
Or by manualy adding into the composer.json
{
"require":{
"nedryse/latte-template-macroset": "~1.0.0"
}
}
Setup
Add following code into the config.neon
common:
extensions:
latteTemplateMacroSet: Nedryse\Latte\Macros\TemplateMacroSetExtension
Usage
The simpliest usage is like the following code:
{template '<strong>{:userName}</strong>', 'userName' => $user->getIdentity()->getId()}
Replacement variables can be given by the array also like in the following code:
{var $replacements = array('userName' => $user->getIdentity()->getId())}
{template '<strong>{:userName}</strong>', $replacements}
Replacement variables can be given from {var ...} or from $template like in the following code:
{var $userName => $user->getIdentity()->getId()}
{template '<strong>{:userName}</strong>'}
Replacements can be overwritten in the order $template, {var ...}, {template ..., replacements} like in the following code:
{var $userName => $user->getIdentity()->getId()}
{template '<strong>{:userName}</strong>', 'userName' => 'test'}
Both macros also support filters like in the following code:
{template '<strong>{:userName}</strong>', 'userName' => 'test'|upper}
Replacements can contain {:nested_placeholders} to be used as customizable template mechanism like in the following code:
{var $idTpl = '<strong>{:userId}</strong>'}
{var $nameTpl = '{:userName}'}
{var $pairTpl = '<li>{:idTpl} - {:nameTpl}</li>'}
{var $usersTpl = '<ul>{:usersListTpl}</ul>'}
{capture $usersListTpl}
{foreach $users as $userId => $userName}
{template $pairTpl}
{/foreach}
{/capture}
{_'User (%s): {:usersTpl}', count($users)}
统计信息
- 总下载量: 18
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: WTFPL
- 更新时间: 2014-12-27