2011-06-29 1 views
6

ブロック(ブロックtrブロック、つまり変換ブロック)の出力に修飾語(私の場合はtruncate)を適用しようとしています。私は修飾子としてtrを持っていないので、HTMLマークアップには便利ではないからです。ブロック出力にSmartyモディファイアを適用する

私はどのような構文を使うべきか、それが許可されているのかどうかはわかりません(与えられたブロックの使い方はちょっとファンキーです)。

そのような何か、それがどんな意味行う場合:あなたがそれらにあなたが好きなように組み合わせカント私の知る限り

{{tr}Really long text I want to be translated then truncated{/tr}|truncate}

答えて

7

{capture assign="var"}{tr}...{/tr}{/capture} 
{$var|truncate} 

しかし、私はあなたのテンプレートファイル内

$smarty->registerPlugin('block', 'tr', 'do_translation', true); 
$smarty->registerPlugin('block', 'truncate', 'do_truncation', true); 

、それをこのように組み合わせる:しかし、あなたは、このように複数のブロックの機能を組み合わせることができます個人的にはブロック機能を切り捨てて作成します。

{truncate}{tr}...{/tr}{/truncate} 
1

を。

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"); 

は、その後、あなたがこのようにSmartyの中でそれを呼び出すことができます::

{tr truncate="1"}Really long text I want to be translated then truncated{/tr} 
0

あなたはそれがやりたい道を私が持っている唯一のアイデアは、あなたの翻訳機能と一緒に、独自の切捨て関数を書くことですこれは構文エラーでSmarty例外をスローします。それは次のように行うことができる

{truncate}{tr}Really long text I want to be translated then truncated{/tr}{/truncate} 
0

これは、Smartyの2とSmartyの3のために動作します:

{t}Really long text I want to be translated then truncated{/t|truncate:10}