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

我可能会把措辞分成以下几个部分:

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?

推荐答案

使用{!! !!}而不是{{ }}来防止逃逸:

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

Laravel相关问答推荐

如何在 laravel 中为另一个用户 session()->forget('cart')?

使用正则表达式 laravel 忘记缓存

阻止用户查看其他用户正在查看的内容的最佳方法是什么?

(1/1) ErrorException ReflectionFunction::__construct() ex

如何获得每种类型的总和

Laravel belongsToMany 关系在两个表上定义本地键

如何处理 Laravel 的 SMTP 驱动程序中的自签名 TLS 证书?

Laravel 5在blade中 echo 包含html的会话变量

实施 Payum/Laravel 定期付款

Laravel - 排序的集合输出不是数组

file_put_content ...无法打开流:Laravel 5 中的权限被拒绝

laravel 5.4 指定的key太长,为什么数字191

Laravel:命令未找到

Laravel Eloquent 模型中的字段

如何清理 Laravel Bootstrap 缓存配置文件?

Elastic search全文与mysql全文?

Laravel 仓库

Laravel - 使用 Eloquent 查询构建器在 Select 中添加自定义列

是否可以在 Laravel 的不同数据库中引用外键?

Laravel如何仅响应没有正文消息的204代码状态