0

I have index.pug and it has some JavaScript in it to access the Google Maps APIs. How do I read the API key in from an external file with pug?

// Add a map script(async='', defer='', src='https://maps.googleapis.com/maps/api/js? key=api_key_goes_here&callback=initMap', type='text/javascript')

  • 1
    What have you tried so far? Questions on SO should demonstrate that the asker has attempted to solve the problem on their own before asking for help. – Sean Jan 23 '18 at 19:48
  • Thanks for the help sean! Appreciate your guidance and helpfulness to help me resolve this issue! Very much appreciated, thanks so much! –  Jan 24 '18 at 22:04

1 Answers1

0

Source : https://stackoverflow.com/a/20343333/8380606

So the following will work:

tmp1.jade

- var label = 'value'
div.anyClass
    include tmp2

tmp2.jade

div.otherClass
    div.label
        #{label}

You can also use mixins to pass variables, they are like functions (you define them first, then call them)

So you could do the following:

tmp1.jade

mixin labeldiv(myLabel)
    div.otherClass
        div.label
            #{myLabel}

div.anyClass
    +labelDiv("the label")

It's worth mentioning that you can also put mixins inside includes, if you want them to be common across multiple templates. You could do this:

myMixins.jade

mixin labeldiv(myLabel)
    div.otherClass
        div.label
            #{myLabel}

tmp1.jade

include myMixins
div.anyClass
    +labelDiv("the label")
Sandeep Ranjan
  • 824
  • 15
  • 33