You can share the server variables to client side by defining attribute on define:vars or <script /> tag in the <style /> template..astro
Read the astro documentation here for more information.
Example as below ( source : Astro documentation )
---
const foregroundColor = "rgb(221 243 228)"; // CSS variable shared
const backgroundColor = "rgb(24 121 78)"; // CSS variable shared
const message = "Astro is awesome!"; // Javascript variable shared
---
/* +++++ CSS variables to share as below +++++ */
<style define:vars={{ textColor: foregroundColor, backgroundColor }}>
h1 {
background-color: var(--backgroundColor);
color: var(--textColor);
}
</style>
/* ++++ Javascript variables to share as below ++++ */
<script define:vars={{ message }}>
alert(message);
</script>
There is also a concept of sharing states using
stated in documentation . It allows sharing states between components at framework level on client-side. Not between client and server.nanostoreTheoretically sharing states from server to client can be done using hydration technique by combining
anddefine:varslibrarynanostoreapi during themapevent may be .onLoad