You can use the render function in a view. You can create a shared view (name it whatever, SharedView, FormHelpersView, etc) and move the rendering there.
# in the template, form.html.eex
render MyApp.SharedView, "radio_group.html", form: f, data: @data, field: :field %>
2 options for the shared view template. Return the html from the view’s render function or create a template.
defmodule MyAppWeb.SharedView do
use MyAppWeb, :view
def parse_function(data) do
...
end
# return html from view function
def render("radio_group.html", %{form: f, data: data, field: field) do
~E(
<div class="form-control">
<%= for l <- parse_function data do %>
<div class="pretty p-default p-curve">
<%= radio_button(f, field, elem(l, 1)) %>
<div class="state">
<label><%= elem(l, 0)%></label>
</div>
</div>
<% end %>
</div>
)
end
end
If you do not want to return the html in the view function you can create a template for it like any other view template/shared/radio_group.html.eex.
Reference:
sigil_E/2
Phoenix View
The examples shown for rendering custom scripts in the phoenix docs for render_existing/3 really helped me.






















