elixir - How to render html template in javascript template in Phoenix Framework -


let's have 2 files, create.js.eex , post.html.eex , want render contents of post.html.eex template inside create.js.eex template. this:

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

the example above doesn't work because need escape quotes , other things in string gets returned , can't find way it

use escape_javascript:

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

you can render_to_string , escape that, there doesn't seem need -- , since returns string, html-escape markup.

actually, exact example in docs:

https://hexdocs.pm/phoenix_html/phoenix.html.html#escape_javascript/1


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -