Blade 模板可重复使用
Blade Templates reusable
我来到 laravel,但在 blade 上遇到了问题。
所以我想让我的 UI 组件可重用,我不想复制和粘贴 HTML。
@include('blocks.js.modal', array(
'title' => "{{ TextHelper::textLang('Guardar llamada','common') }}",
'close' => "{{ TextHelper::textLang('Cerrar','common') }}",
'save' => "{{ TextHelper::textLang('Guardar','common') }}"
)
)
我向我的部分模板传递了一个函数助手来使用这个变量,但我无法工作
还有另一种方法,我想我错过了一些东西。
您在 PHP 样式数组中使用了 blade 语法。像这样更改您的代码:
@include('blocks.js.modal', [
'title' => TextHelper::textLang('Guardar llamada','common'),
'close' => TextHelper::textLang('Cerrar','common'),
'save' => TextHelper::textLang('Guardar','common')
])
您必须提供一个数组并在您的 Balde 模板中调用 TextHelper:
@include('blocks.js.modal', array(
'title' => ['Guardar llamada','common'],
'close' => ['Cerrar','common'],
'save' => ['Guardar','common']"
)
)
然后你可以像这样调用 Blade:
"{{ TextHelper::textLang($title[0],$title[1]}}"
希望对您有所帮助
我来到 laravel,但在 blade 上遇到了问题。
所以我想让我的 UI 组件可重用,我不想复制和粘贴 HTML。
@include('blocks.js.modal', array(
'title' => "{{ TextHelper::textLang('Guardar llamada','common') }}",
'close' => "{{ TextHelper::textLang('Cerrar','common') }}",
'save' => "{{ TextHelper::textLang('Guardar','common') }}"
)
)
我向我的部分模板传递了一个函数助手来使用这个变量,但我无法工作
还有另一种方法,我想我错过了一些东西。
您在 PHP 样式数组中使用了 blade 语法。像这样更改您的代码:
@include('blocks.js.modal', [
'title' => TextHelper::textLang('Guardar llamada','common'),
'close' => TextHelper::textLang('Cerrar','common'),
'save' => TextHelper::textLang('Guardar','common')
])
您必须提供一个数组并在您的 Balde 模板中调用 TextHelper:
@include('blocks.js.modal', array(
'title' => ['Guardar llamada','common'],
'close' => ['Cerrar','common'],
'save' => ['Guardar','common']"
)
)
然后你可以像这样调用 Blade:
"{{ TextHelper::textLang($title[0],$title[1]}}"
希望对您有所帮助