刀片模板

时间:2016-02-27 18:09:27

标签: php laravel

我从控制器发送变量response到我的视野。

所以在我看来,如果我这样做:

{{response}}

我可以看到响应,所以就在那里。

然而response是一个json格式的字符串,所以我需要解析它,

我想在刀片中执行此操作。

我试过这个

<!DOCTYPE html>
<html>
<head>
<title>Master Response</title>
</head>
<body>
{{
        $json_a = json_decode($response, true);
        $hits = $json_a['hits']['hits'];
}}
</body>
</html>

但是我收到了这个错误

Whoops, looks like something went wrong.

1/1
FatalErrorException in 95df32e49f76c09bb366fa2eba52e460d30085dd.php line 7:
parse error
in 95df32e49f76c09bb366fa2eba52e460d30085dd.php line 7

1 个答案:

答案 0 :(得分:0)

刀片系统使用{{ $var }}来回显数据。如果你想在刀片中用PHP做事,你需要使用PHP标签,如下所示:

<!DOCTYPE html>
<html>
<head>
    <title>Master Response</title>
</head>
<body>
<?php
        $json_a = json_decode($response, true);
        $hits = $json_a['hits']['hits'];
?>
</body>
</html>