I wonder if there is a way to render phoenix templates when adding content via websockets? What is the way to go if I want to add some complicated html structure that I have as a template using websockets without duplicating this structure in the javascript code?
The only way to do it that I see is to generate the template html in the controller with something like this:
def create(conn, params) do
#some code
Endpoint.broadcast!("user_room:123", "new_comment", %{comment_content: MyApp.PostView.render(conn, "comment.html", comment: comment)})
#some code
end
and then add this generated content to the page in the javascript file handling the channel response.
I havent tried it yet so it may not even work but I wonder if there is a more proper way to do that? If it's possible in the first place?