2015-10-03 102 views
1

假设我有2个文件,create.js.eexpost.html.eex,我想在create.js.eex模板中呈现post.html.eex模板的内容。事情是这样的:如何在Phoenix Framework中的javascript模板中呈现html模板

$("#something").append("<%= safe_to_string render "post.html", post: @post %>"); 

上面的例子不工作,因为我需要逃避被返回的字符串中的报价和其他的东西,我无法找到一个方法来做到这一点

回答

5

你可以使用render_to_string

Phoenix.View.render_to_string(MyApp.PageView, "index.html", foo: "bar") 

请注意,这可能会使您XSS。