我正在尝试将一些变量从我的 NodeJS index.js 文件解析到我的 profile.pug 文件。 这是来自 index.js 的代码片段:
app.get('/profile', requiresAuth(), async (req, res) => {
var song_info=await getSong();
res.render('profile', { user: req.oidc.user, details: song_info[1], img_album_cover: song_info[4], song_src: song_info[5]});
});
这里来自 profile.pug:
extends ../components/layout
block content
if user
div.swipe_card
div.flex-container-vert
div.flex-container-hort
div(class="card" style="top: 10%")
div(class="photo")
img(src=img_album_cover alt="Coverphoto" width="425px" height="425px")
p(class="details_text" id="id_details_text" alt="TEXT")=details
audio(controls="" class="player")
source(src=song_src type="audio/mp3")
form(action="/dislike" method="POST")
input(type="image" src="../images/cross_rand.png" alt="Submit" class="left_button")
form(action="/like" method="POST")
input(type="image" src="../images/note_rand.png" alt="Submit" class="right_button")
变量有:details、img_album_cover、song_src 输入的图片也没有显示,但这是一个小问题。
我试过的: 我尝试在 index.pug 文件中传递 vars 并且它起作用了,这里是代码,首先是 index.js 然后是 index.pug:
app.get('/', (req, res) => {
res.render('home',{siteTitle: "TITLE420"});
});
block variables
doctype html
html.h-100(lang="en")
head
//meta tags
//link to icon
meta(name="theme-color", content="#000")
//link to bootstrap
//css
script(src="https://kit.fontawesome.com/3116610f1c.js", crossorigin="anonymous")
title=siteTitle
body.h-100
block layout-content