Join the AI Workshop and learn to build real-world apps with AI. A hands-on, practical program to level up your skills.
NOTE: This approach may not work in all Astro versions. Consider using a separate
config.mjsfile instead of importing fromastro.config.mjs.
I needed a global flag on my site, and when that flag was true I wanted to display something. If false, I wanted that information to be hidden, on multiple page components.
So, a single flag to change how the site looked.
Here’s what I did.
I put that flag in astro.config.mjs:
export default /** @type {import('astro').AstroUserConfig} */ ({
renderers: ['@astrojs/renderer-react'],
devOptions: {
tailwindConfig: './tailwind.config.cjs',
},
signupsOpen: false,
})
Note the last entry signupsOpen. That’s the one I added.
Then I referenced that value in every component where I wanted to use it.
Something like this:
---
import Config from '../../astro.config.mjs'
---
<div>
{Config.signupsOpen && <p>flag is true</p>}
</div>