Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 72388

How do I pass a variable into an ejs script tag attribute?

$
0
0

I'm trying to pass an API Key - which I call on the server side and pass through to an EJS file - into the src attribute on a script tag. When I console.log the string it prints exactly how'd I want but I can't update the src attribute the way I need to, to be able to run the script. I've tried passing in the string variable directly, using template literals etc. Any ideas?

<script>
        let myKey = <%- JSON.stringify(key) %>
        let string = `https://maps.googleapis.com/maps/api/js?key=${myKey}&callback=initMap`
    </script>

    <script src= https://maps.googleapis.com/maps/api/js?key=${myKey}&callback=initMap
    async defer> </script


Viewing all articles
Browse latest Browse all 72388

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>