Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Layout attribute #2173

Open
eelcoj opened this issue Dec 1, 2024 · 1 comment
Open

Layout attribute #2173

eelcoj opened this issue Dec 1, 2024 · 1 comment

Comments

@eelcoj
Copy link
Contributor

eelcoj commented Dec 1, 2024

Feature request

I want to check how you feel about adding support for a "layout" attribute in ViewComponent. This should work similarly to Rails partials' layout attribute:

<%= render partial: "user", layout: "shared/admin" %>

This would wrap the user partial with app/views/shared/_admin.html.erb.

For ViewComponent this could be:

<%= render(UserComponent.new(user: @user, layout: AdminComponent)) %>

Motivation

This would come in handy most often when rendering a collection. The ViewComponent renders the collection (eg. li, but not the wrapping element (eg. <ul>).

The only mention of this seems to be here: #198

if this sounds interesting, I am happy to spend some time on it.

@reeganviljoen
Copy link
Collaborator

reeganviljoen commented Dec 2, 2024

@eelcoj, this is possible with current features, like the slot api for example

<%= render(AdminComponent.new()) do |c| %>
  <% c.with_body do %>
     <%= render(UserComponent.new(user: @user) %>
  <% end %> 
<% end %> 

all that said the example above is a lot more dense and could possibly benefit from a layout api, I would like to however ask @joelhawksley what his thoughts are.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants