#Is it possible to have an Astro component place itself into a named slot of it's parent by default?

1 messages · Page 1 of 1 (latest)

main yew
#

Say we had a component usage like:

<Hero>
   <HeroPreTitle />
</Hero>

where Hero had a slot called pre-title and a default non-named slot, could HeroPreTitle automatically place itself into the pre-title slot of Hero without needing to provide the name attribute on HeroPreTitle?

grand epochBOT
#

Hi @main yew. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

No, to place the HeroPreTitle component into the pre-title slot of the Hero component, you need to provide the slot attribute with the corresponding slot name on the HeroPreTitle component. Without the slot attribute, the HeroPreTitle component will be placed in the default (unnamed) slot of the Hero component.

Here's how you should use the slot attribute:

<Hero>
   <HeroPreTitle slot="pre-title" />
</Hero>

For more information on named slots, refer to the Astro documentation on named slots (https://docs.astro.build/en/core-concepts/astro-components#named-slots).

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

Astro Documentation

An intro to the .astro component syntax.