#how to access astro variable inside <script> tag
3 messages · Page 1 of 1 (latest)
Hi @neat valve. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
To access Astro variables inside a <script> tag, you can use the define:vars directive to pass server-side variables from your component frontmatter into the client <script> tag. Here's an example:
---
const message = "Astro is awesome!";
---
<script define:vars={{ message }}>
alert(message);
</script>
Keep in mind that using define:vars on a <script> tag implies the is:inline directive, which means your scripts won't be bundled and will be inlined directly into the HTML.