【问题标题】:Laravel: How to I pass a Blade template to the client side via JSON?Laravel:如何通过 JSON 将 Blade 模板传递给客户端?
【发布时间】:2012-11-24 17:40:46
【问题描述】:

我希望将包含一些 HTML 的 JSON 对象传递给我的客户端应用程序。我正在使用 Laravel 3.2.12,我是新手。我知道问题出在我的 View::make 指令中。那么哪个是正确的指令呢?

在 My_Controller 中:

public function get_all()
{
    return Response::json(array(
        array('name' => 'OR', 'category' => 'Logical', 'form_controls' => View::make('modules.or'))
    ));
}

在views/modules/or.blade.php中:

<span>test</span>

在views.js中:

$('#element').html(Mustache.to_html(ModuleTemplate, {some: 'stuff'}, { custom: this.model.get("form_controls") }));

在view.mustache中:

...
{{>custom}}
...

JSON 中的 HTML 应该被 mustache.js 作为部分解析。

【问题讨论】:

    标签: json client-side mustache laravel


    【解决方案1】:

    我认为您正在寻找的是 View::render();

    http://laravel.com/api/source-class-Laravel.View.html#311

    据我所知,View::make 返回一个完整的响应对象,这不是您想要的。

    【讨论】:

    • 谢谢,谢谢。文档对此不够清楚。当然,责怪文档总是很容易的。
    • 这个助手没有任何文档。通过深入研究源代码找到了这个助手。不过确实应该记录在案。
    猜你喜欢
    • 2015-12-02
    • 2014-07-17
    • 2014-07-17
    • 2016-02-05
    • 2013-04-13
    • 1970-01-01
    • 2015-03-06
    • 2021-06-25
    • 1970-01-01
    相关资源
    最近更新 更多