close

如何在Laravel blade中使用include blade並且帶參數進去?

在include func中帶入第二個參數,把要帶進去的參數名稱和值用陣列包起來傳入。

ex:

@include('layouts.article', [
    'mainTitle' => "404, page not found",
    'mainContent' => "sorry, but the requested page does not exist :("
])

--

轉自 https://stackoverflow.com/questions/29739745/laravel-blade-passing-variable-with-string-through-include-causes-error

It's not a bug but a limitation of blade syntax due to regex. Solution came from github:

The problem is using multi-line. You can only use a single line to [pass variables] in Blade, since syntax is limited [by regular expressions]

Try the code below and you should be good to go:

@include('layouts.article', ['mainTitle' => "404, page not found", 'mainContent' => "sorry, but the requested page does not exist :("])

--

 

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 dizzy03 的頭像
    dizzy03

    碎碎念

    dizzy03 發表在 痞客邦 留言(0) 人氣()