0

I am using Jade language in my code. I have written some jade functions with the help of mixin syntax. Now I wanted to call that functions from javascript code.

How do I call ? Can anybody help me please.

ul.grid
  each product in products
    +productItem(product)
mixin productItem(item)
  li(style="border: 1px solid #ddd;margin-top: 35px;") #{item}
script(type='text/javascript').
 console.log("Welcome");
 <<How to call productItem function >>

I wanted to call the productItem function from script tag where I written <> this sentence. Please help me.

1 Answer 1

1

You cannot call Pug mixins with JS. And mixins aren't functions either. That said, you can include Javascript in a mixin like this:

mixin productItem(item)
   li(style="border: 1px solid #ddd;margin-top: 35px;") #{item}
   script.
      console.log("This will be logged once each time this mixin is called.");

Is it correct to assume, that you would like to include JS in your PUG mixin?

Btw, Jade is now Pug. Cheers!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.