問(wèn)題描述
在 Laravel 5.0.27 中,我包含一個(gè)帶有變量和以下代碼的視圖:
In Laravel 5.0.27 I am including a view with with a variable and the following code:
@include('layouts.article', [
'mainTitle' => "404, page not found",
'mainContent' => "sorry, but the requested page does not exist :("
])
我收到以下錯(cuò)誤...
FatalErrorException 語(yǔ)法...錯(cuò)誤,意外的','
FatalErrorException syntax ... error, unexpected ','
我已經(jīng)確定錯(cuò)誤僅來(lái)自mainContent"變量字符串中的(",當(dāng)我刪除("時(shí),錯(cuò)誤消失,一切正常.我在文檔中找不到任何內(nèi)容在線列出的此錯(cuò)誤或任何類似錯(cuò)誤.
I've narrowed down that the error is solely from the "(" in the "mainContent" variable string, and when I remove the "(" the error disappears and everything runs fine. I can't find anything in documentation on this or any similar errors listed online.
有誰(shuí)知道這是預(yù)期行為還是應(yīng)該報(bào)告的錯(cuò)誤?
Does anyone know if this is expected behavior or if this is a bug that should be reported?
非常感謝您的時(shí)間!
推薦答案
這不是 bug,而是由于正則表達(dá)式導(dǎo)致的 Blade 語(yǔ)法限制.解決方案來(lái)自 github:
It's not a bug but a limitation of blade syntax due to regex. Solution came from github:
問(wèn)題是使用多行.您只能使用一行[傳遞變量] 在 Blade 中,因?yàn)檎Z(yǔ)法受到 [通過(guò)常規(guī)表達(dá)]
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]
試試下面的代碼,你應(yīng)該很高興:
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 :("])
這篇關(guān)于Laravel Blade 通過(guò)@include 傳遞帶有字符串的變量會(huì)導(dǎo)致錯(cuò)誤的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!