#How to access data in astro

3 messages · Page 1 of 1 (latest)

acoustic spade
#

I want to access <MainLayout title="Home"> title in my mainLayout

cerulean pawnBOT
#

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

#

In Astro, you can access the data passed to a component through Astro.props. In your case, if you want to access the title prop in your MainLayout component, you can do it like this:

---
// This is the script part of your Astro component
const { title } = Astro.props;
---

<!-- This is the HTML part of your Astro component -->
<h1>{title}</h1>

In the script part of your Astro component, Astro.props is an object that contains all the props passed to the component. By destructuring Astro.props, you can directly access the title prop.

This is mentioned in the Astro documentation here (https://docs.astro.build/en/tutorial/4-layouts/1/).

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