V
V
Vadim Belkin2015-05-18 21:36:14
Pug
Vadim Belkin, 2015-05-18 21:36:14

Why doesn't passing an object from a variable to a mixin work?

Building jade with gulp. Got a mixin

mixin test(data)
    .block
        .block_heading #{data.heading}
        .block_text #{data.text}

When data
+test({heading: "Heading", text: "Text"})
is transferred to it, what is needed comes out.
But if you create a variable with data and pass it to the mixin
- var dataTest = {heading: "Heading", text: "Text"}
+test(dataTest)

an error occurs
events.js:85
      throw er; // Unhandled 'error' event
            ^
TypeError: test.jade:3
    1| mixin test(data)
    2|     .block
  > 3|         .block_heading #{data.heading}
    4|         .block_text #{data.text}

Explain what I'm doing wrong, and is it possible to pass variables to the mixin at all?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
Homsa Toft, 2015-05-18
@BelkinVadim

Hmm.. works for me.

mixin test(data)
    .block
        .block_heading #{data.heading}
        .block_text #{data.text}

doctype html
html(lang="en")
    head
        title
    body
        - var dataTest = {heading: "Heading", text: "Text"}
        +test(dataTest)

<!DOCTYPE html>
<html lang="en">
  <head>
    <title></title>
  </head>
  <body>
    <div class="block">
      <div class="block_heading">Heading</div>
      <div class="block_text">Text</div>
    </div>
  </body>
</html>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question