dtkago3208
2017-04-20 08:09
浏览 133
已采纳

在Laravel中将@lang作为@section参数传递

I am working on a Multi Lingual Application in Laravel 5.4

template.blade.php

<title>@yield('title')</title>

Then in other pages, I am trying to set the tile dyamically based on user locale. It throws error when I try to use the following:

@section('title',{{ __("dashboard") }})

or

@section('title', @lang("dashboard"))

This is the error:

Parse error: syntax error, unexpected '<'

Can any one tell how to pass @lang or __('') as paramater in a @section()

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dpxw17759 2017-04-20 08:17
    已采纳

    What you have as a parameter is supposedly php. Therefore, when you put @lang or {{}}, it will open php tags inside already opened php tags.
    Therefore, what you can do is just put __() without the brackets. Just like that :

    @section('title', __('dashboard'))
    
    打赏 评论
  • dsvcqvp139098 2017-04-20 08:16

    You can use trans instead of lang decorators :

    @section('title', trans("dashboard"))
    

    Or

    You can also use __ function like this :

    @section('title', __("dashboard"))
    

    You don't need to use {{}} as you are not using it inside another directive.

    打赏 评论

相关推荐 更多相似问题