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

Pass @lang as @section parameter in Laravel

我正在 Laravel 5.4

开发多语言应用程序

template.blade.php

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

然后在其他页面中,我尝试根据用户区域动态设置磁贴。当我尝试使用以下内容时它会抛出错误:

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

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

这是错误:

Parse error: syntax error, unexpected '<'

谁能告诉我如何在 @section()

中将 @lang__('') 作为参数传递

您可以使用 trans 而不是 lang 装饰器:

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

您也可以像这样使用 __ 函数:

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

您不需要使用 {{}},因为您没有在另一个指令中使用它。

你的参数应该是 php。因此,当您放置 @lang 或 {{}} 时,它会在已打开的 php 个标签中打开 php 个标签。
因此,您可以做的就是将 __() 不带括号。就这样:

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

实际上,@section并没有提供显式的参数传递。

但是,你想要的是将参数传递给包含的模板,而不是传递给 yield,所以在 blade 的开头:

@extends('my_parent',['my_parameter'=>'my_value'])