php - 如何在 laravel 的 @include() 中使用 {{ }} 发送参数
问题描述
我想在 Laravel 的 @include() 中将路由作为参数发送。我正在尝试使用 {{ }} 发送参数以将其作为 href 值,但我收到错误消息。有没有办法把'{{}}'放在字符串中?
这就是导致错误的原因:
@include('includes.content.single-article', ['href' => '{{ route('article') }}'])
在 single-article.blade.php 中应该是这样的:
<a class="card-link btn btn-warning" href="{{ $href }}">more<span class="icon icon-plus"></span></a>
它应该像这样工作:
<a class="card-link btn btn-warning" href="{{ route('article') }}">more<span class="icon icon-plus"></span></a>
我得到的错误:
ParseError 语法错误,意外的“文章”(T_STRING),期待“]”
解决方案
您不需要发送变量。@include
是“复制/粘贴”(相同@extend
)。
这样做:
@php($href=route("article"))
@include("includes.content.single-article")
就这样。现在您的刀片includes.content.single-article
知道$href
.
如果你真的只需要这个刀片的变量
@include("catalog.task.foo", ["href" => route("purchase.provider")])
当您使用刀片指令时,您在上下文中,如果您不需要字符串PHP
,请不要使用。"
你可以
@include("catalog.task.foo", ["href" => 45+58])
并且会做数学
推荐阅读
- python - Python NameError:没有为类中的成员方法定义名称'methodA'
- r - 森林(relative.effect())/结果错误[[“模型”]]:下标超出范围
- php - .htpasswd 的 WooCommerce 客户注销问题
- python - 是否可以使用 selenium 在请求标头中转储厨师?
- c - MinGW/GCC GLFW 链接器问题 - 未定义对“glfwInit”的引用
- node.js - 子进程不会在 heroku 主机上启动
- windows - Windows10 docker:Grafana 无法访问 influxdb-502 Bad Gateway
- monads - 如何在 PureScript 中为 SimpleJSON 创建自定义解析器 Monad?
- amazon-web-services - 如何让 AWS ECS 在关键时刻不停机?
- scope - 在函数内的 for 循环内修改变量