-
Notifications
You must be signed in to change notification settings - Fork 10.1k
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
Proposal: View Component Slots #4901
Comments
Thanks for well-thought-out request, @rdlaitila. |
Thanks for your proposal, @rdlaitila. |
This is something I was looking for for quite a while now. Why is this closed, now that 3.0 is released, wouldn't it make sense to reevaluate priorities? |
@SteveSandersonMS please correct me, if I'm wrong, but if I remember correctly, this is possible today using |
@mkArtakMSFT thanks for the quick reply! RenderFragment seems to be blazor related in regard to the new razor facilities? Do you have any documentation on how to use RenderFragment within SSR Asp.Net Core MVC View Components along with their associated tag helper invocation? Specifically: The original use case is to give a more nested component-based approach when using traditional MVC. Using the newer razor components under blazor (server hosted) brings on new dependencies such as required websockets and SignalR which may not fit into some application stacks. |
@rdlaitila, it seems I've got confused about this issue being a request for Blazor. Please ignore my last comment. |
@mkArtakMSFT That'd be enough to get the ball rolling for slots as a proper community add-on. Right now, any implementation of this feature eventually hits the wall where the |
Feature Proposal
Provide a built-in or otherwise framework supplied mechanism for View Components, when rendered via a tag helper, to render user-supplied child content that can be injected into the View Component's view template in pre-defined locations
Use Case
When building component based presentation a number of useful features present in other component inspired frameworks are missing in Mvc:
Allowing view components to accept child content provides new ways to build complex component driven presentation.
Use Case Example
Within some calling view, instantiating a View Component via a tag helper and supplying child content:
Calling View:
The ViewComponents view template would provide the slot mechanism to place the user defined child content:
View Component View Template:
The View Component slotting mechanism will take care of rendering the user supplied child content into the correct slots in the View Component's user defined slot locations. Example output of the following:
Inspiration
Content slotting or otherwise rendering user supplied child content in a parent template is a known and useful pattern seeing fair usage today:
Primary insipriation is from the web component HTML templates spec
Requirements
Some potential requirements determined while researching this proposal:
<vc:[component_kebab_case_name]>
<vc:slot>
) to mark locations in a View Component's view template where user supplied content can be placedExperimental Implementation
To facilitate interest in this proposal a simple experiement was built to showcase the View Component Slotting mechanism in action. This experiement does not necessarly implement all identified requirements and is not guarenteed to be bug-free.
https://github.com/rdlaitila/AspNetCore.Mvc.ViewComponentSlots
what should work:
<vc:slot>
<vc:slot>
element in the View Component's view template where a slot with attributename="[slot_name]"
exists (ex:<vc:slot name="some-slot"
>)differences:
kebab-case
orPascalCase
where the tag contains attributevc
(ex:<my-custom-component vc>
or<MyCustomComponent vc>
)<vc:slot>
as well as the slot selector attributevc:slot="[name]"
simply to match the existing View Component Tag Helper naming convention<vc:[component-kebab-name]>
for consistency. There is no reason we could not adopt the current web component slot naming convension, or using some other name entirly.Author's Contribution
Unfortunatly I will be time limited to focus on a core contribution of View Component Slots to aspnet/Mvc and don't posses deep enough knolwedge of contribution guidelines or the Mvc sources to properly facilitate implementation of this proposal.
I can however allocate some time to improve the experimental proposal implementation as needed and respond to community issues and pull requests on a best-effort basis. I hope the experimental implementation can validate that this use case is valid and valuable to others.
Community Contribution
I would be excited to see community members either help improve the example implementation or help propose how to best implement such a feature into the Mvc core.
The text was updated successfully, but these errors were encountered: