Skip to content

Split Templates for Improved Customizability #2823

@goosys

Description

@goosys

What would you like to be able to do? Can you provide some examples?

I would like the templates to be more finely divided to improve customizability.
By splitting them, we can always call the common parts like Label + render_field, allowing for a custom design while keeping the core functionality consistent.

How could we go about implementing that?

I tried splitting the templates with a simple approach.
By using render with collection and layout, we can write it more concisely without each.
goosys@31a27e9

With this change, for example, it becomes easier to structure a custom design like this:

# Helper
def render_item_unit(attribute_field)
  render(
    partial: 'resource_item',
    layout: 'resource_item_unit',
    locals: local_assigns.merge(attribute: attribute_field)
  )
end
# admin/users/show.html.erb
<%= content_for(:main) %>
   <section class="main-content__body">
     <figure><%= render_field(page.attributes[:icon]) %></figure>
     <div>
       <%= render_item_unit(page.attributes[:name]) %>
       <%= render_item_unit(page.attributes[:email]) %>
    </div>
   </section
<% end %>

Can you think of other approaches to the problem?

I think we can make it even more convenient with Renderable since Rails 6.1, but in any case, I believe splitting it into this level of granularity is necessary.

Additionally, it would be beneficial to split not only show but also form, collection, and search_bar.

Would you be open to considering this?
If you have any specific partial file names in mind, please let me know—I’d be happy to work on this and submit a PR!

Metadata

Metadata

Assignees

No one assigned

    Labels

    views-and-styleshow administrate looks and is interacted with

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions