#Loading JavaScript only if condition is true

4 messages · Page 1 of 1 (latest)

gusty furnace
#

Hey astronauts,
is it possible to render a script only if the condition is set to true, something like this ?
I get an error that i can not import things from outside a module, is there a way to fix this or a work around?

---
import { CONDITION } from 'Theme_Config'
---

<!-- Some HTML stuff -->
<nav>
  <a href="!#">Link</a>
  <a href="!#">Link</a>
  <a href="!#">Link</a>
</nav>

<!-- Get the script if condition is set to true -->
{
  CONDITION && (
  <script>
    import { VALUE_FROM_CONFIG } from 'Theme_Config'

    // Do things with VALUE_FROM_CONFIG
  </script>
)}
loud wasp
gusty furnace
#

good idea, i will give it a try

gusty furnace