我试图通过仅包含一个混合物的哈巴狗文件来提供上下文。但是,当我尝试渲染该文件时,它无能为力。
This is my express route
app.post('/comment', (req, res) => {
const test = {
text: 'working',
};
res.render('comment-section', test);
});
这是我的哈巴狗文件混音
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
如何使Pug Mixin从路线上获取上下文(测试对象(并使用它。预先感谢!
不是在帕格(Pug
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
现在您可以按以下方式使用它
- var text = '<- var should already exist when locally provided'
#comment-section
+comment(text)