typescriptastrojs

How to Use Script tag with custom attributes in the Layout.astro file


I'm using astro.build my static site.

I want to add a script with a custom attribute in the head tag of all the pages on my site. The script tag is as follows:

<script data-grow-initializer="">!(function(){window.growMe|| bla bla</script>

I added this script tag in the layout.astro file. But after the site was built by Astro, the script tag didn't contain the attribute data-grow-initializer=""..

This attribute was expected by another program for correct functioning.

I'm using the astrowind theme.

Please help.


Solution

  • Instead of adding the script code directly in the layout.astro file, I followed the below steps and it is working now:

    1. Created a separate component for the script
    2. Added the component in the layout.astro file

    Now the script is included in all the pages with the custom attributes.