我想将内联样式添加到YII t(';';)


I want to add inline style to YII t(' ')

我想为该文本添加样式"float:right">。我尝试了一些方法,但没有成功。我应该如何为此添加内联css。

public function title()
{
    return $this->t('You have {amount} of credit', 
    array('{amount}' => m('payment')->format(wm()->get('payment.helper')->credit())),
    array('style'=>'float:right'));
}

你能给我一个提示吗?

Yii翻译函数如下所示:Yii::t('category', 'message', '['params' => 'value''])。所以你需要style在你的信息中进行翻译。
Yii::t(
    'admin',
    'You have <span style="{style}">{amount}</span>',
    [
        '{style}' => 'color: red;',
        '{amount}' => 'Test',
    ]
);
-> <span style="color: red;">Test</span>

同意@Justinas的观点(非常感谢你的例子,它真的很有效(,但你的代码中有一个小错误:

'{style}' => 'color: red;'  // in this case style would not be applicable to a span

必须如此:

'style' => 'color: red;'

对我的案例进行了测试,效果肯定。