0

I am trying to give context through express route to pug file containing only one mixin. But when i try to render that file, it just do nothing.

This is my express route

app.post('/comment', (req, res) => {
      const test = {
          text: 'working',
      };
      res.render('comment-section', test);
});

And here is my pug file mixin

mixin comment()
  div.comment-content
    div.row
        div.col-lg-1
          a(href="#")
              img(src="img/default_profile.jpg").comment-profile-img
        div.col-lg-10
          p.user-comment
              | Comment //- <--- Here i would like to use the test object this way {#text}
    div
      textarea(name="post_content" placeholder="Comment something" rows="1").comment-textarea.post-comment-message

How can i make the pug mixin take the context (test object) from the route and use it. Thanks in advance!

Georgi Enev
  • 23
  • 1
  • 9

1 Answers1

0

Not pro at pug but I think you should provide the arguments you want to use explicitly:

mixin comment(text)
  div.comment-content
    div.row
      div.col-lg-1
        a(href="#")
          img(src="img/default_profile.jpg").comment-profile-img
      div.col-lg-10
        p.user-comment= text //- or #{text}, assuming {#text} was a typo
  div
    textarea(name="post_content" placeholder="Comment something" rows="1").comment-textarea.post-comment-message

Now you can use it as follows

- var text = '<- var should already exist when locally provided'
#comment-section
  +comment(text)