Given this Astro component using slots, what will appear inside the <main> tag when rendered?
/* Parent.astro */ --- import Layout from './Layout.astro'; --- <Layout> <p>Hello, world!</p> </Layout> /* Layout.astro */ --- --- <html> <body> <header>Site Header</header> <main><slot /></main> <footer>Site Footer</footer> </body> </html>
Remember that the default slot renders whatever is placed between the component tags.
The <slot /> tag in Layout.astro acts as a placeholder for the content passed between <Layout> tags. Here, <p>Hello, world!</p> is passed and rendered inside <main>.
Choose the correct syntax to define a named slot called sidebar inside an Astro component.
Named slots use the name attribute on the <slot> tag.
In Astro, named slots are declared with <slot name="slotName" />. The other options use incorrect attributes or tags.
Consider this Astro component and its usage. What will be the final HTML output?
/* Card.astro */ --- --- <article> <header><slot name="title" /></header> <section><slot /></section> <footer><slot name="footer" /></footer> </article> /* Usage.astro */ --- import Card from './Card.astro'; --- <Card> <p>This is the main content.</p> <h2 slot="title">Card Title</h2> <small slot="footer">Footer text</small> </Card>
Remember that unnamed content goes to the default slot, and named content goes to matching named slots.
The <h2> with slot="title" fills the <slot name="title" /> in header. The <p> without slot fills the default slot in section. The <small> with slot="footer" fills the footer slot.
Given this Astro component and usage, why does the content for the named slot header not appear?
/* Layout.astro */ --- --- <div> <slot name="head" /> <slot /> </div> /* Page.astro */ --- import Layout from './Layout.astro'; --- <Layout> <h1 slot="header">Welcome</h1> <p>Main content here.</p> </Layout>
Check the spelling of the slot names in both component and usage.
The component defines a slot named 'head', but the usage provides content for a slot named 'header'. Since names differ, the named slot content is not rendered.
Consider this Astro component with fallback content inside a slot. What will be rendered if the parent component does NOT provide any content for the slot?
<!-- Fallback.astro -->
<article>
<slot>
<p>No content provided.</p>
</slot>
</article>Slots can have default content that shows if no content is passed in.
Astro renders the fallback content inside the slot if no content is provided by the parent. Here, the paragraph 'No content provided.' will appear inside the article.
