如何在Laravel本地化文件中使用HTML标签? [英] How can I use HTML tags in a Laravel localization file?

查看:147
本文介绍了如何在Laravel本地化文件中使用HTML标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试利用Laravel的本地化功能,但是我需要能够强调或加粗短语的一部分.在语言文件中插入HTML标记会导致将其输出到刀片时被转义.

I'm trying to utilize Laravel's localization feature, but I need to be able to put emphasis or bolden a portion of a phrase. Inserting a HTML tag into the language file causes it to be escaped when outputted to a blade.

例如,这是我的语言文件条目:

For example, here is my language file entry:

return [
    'nav' => [
        'find' => '<strong>Find</strong> Your Home',
    ]
];

当我从刀片中调用它时:(我也尝试过使用三括号).

When I call it from within a blade: (I've tried using triple braces as well.)

{{ trans('base.nav.find') }}

它输出:

&lt;strong&gt;Find&lt;/strong&gt; Your Home


我可能会像这样对短语进行分句


I could potentially split the phrasing up like:

return [
    'nav' => [
        'fyh' => [
            'find' => 'Find',
            'yh'   => 'Your Home',
        ]
    ]
]

然后输出:

<strong>{{ trans('base.nav.fyh.find') }}</strong>{{ trans('base.nav.fyh.yh') }}

但是这似乎太过分了.有更好的解决方案吗?

But that seems like overkill. Any better solutions?

推荐答案

使用{!! !!}而不是{{ }}来防止转义:

Use {!! !!} instead of {{ }} to prevent escaping:

{!! trans('nav.find') !!}

这篇关于如何在Laravel本地化文件中使用HTML标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆