I'm trying to apply a modifier (truncate
, in my case) to the output of a block (a tr
block, that is, a translation block). I don't have tr
as a modifier because it's not convenient for HTML markup.
I don't really know what kind of syntax I should use, nor if it's allowed (given, my usage of blocks might be a bit funky).
Something like that, if it makes any sense:
{{tr}Really long text I want to be translated then truncated{/tr}|truncate}
It could be done like this:
{capture assign="var"}{tr}...{/tr}{/capture}
{$var|truncate}
But I personally would create truncate block function and do this
{truncate}{tr}...{/tr}{/truncate}
Afaik you cant combine them the way you like. The only idea I have, is to write your own truncate Function together with your translate function:
function do_translation($params, $content, $smarty, &$repeat) {
if (isset($content)) {
$options = $params["options"];
$content = yourTranslateFunction($content);
if ($options['truncate']) $content = yourTruncateFunction($content);
return $content;
}
}
$smarty->registerPlugin("block", "tr", "do_translation");
Then you could invoke it in Smarty like this:
{tr truncate="1"}Really long text I want to be translated then truncated{/tr}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With