Replicating Rails `content_for()` in Phoenix
Typically in Rails layout you would do sth similar to this:
<%= yield :nav_actions %>
then in view (i.e. “resource_abc/show”):
<% content_for :nav_actions do %>
<!-- whatever -->
<% end %>
To replicate this behavior in Phoenix use render_existing/3
In layout:
<%= render_existing @view_module, "nav_actions." <> @view_template, assigns %>
Then in your template folder (“resource_abc/“) you need to define extra file nav_actions.show.html.eex
(for show action) -
it will render content of nav_actions.show
only if the file exists.
If you want to render nav_actions
for all resource actions just skip @view_template
:
<%= render_existing @view_module, "nav_actions", assigns %>
In this case file should be named nav_actions.html.eex
.