简体   繁体   English

在 Pug/Jade 模板引擎中显示图像

[英]Display image in Pug/Jade template engine

I am trying to display images from an object for get Http method ('/campgrounds').我正在尝试从对象中显示图像以获取 Http 方法('/campgrounds')。 Get Http Method with campgrounds array have 3 objects with 2 properties How to display the images links in the home page ? Get Http Method with campgrounds array has 3 objects with 2 properties 如何在主页中显示图像链接?

app.set("view engine", "pug"); 
app.get('/campgrounds', (req, res) => {
    const campgrounds = [
        {
            Name: "Name1", 
            Image: "https://images.unsplash.com/photo-1571687949921-1306bfb24b72?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=500&q=60"
        },
    ]; 
    res.render("campgrounds", { campgrounds: campgrounds });
});

This is campgrounds.pug page这是campgrounds.pug页面

html 
  head 
  body 
      h1 This is the Campgrounds Page!  
       each val in campgrounds  
        ul
         li=val.Name 
         li=img(src=val.Image) // get the images as stirng links 
             

Indent the img tag:缩进img标签:

each val in campgrounds  
  ul
    li=val.Name 
    li
      img(src=val.Image)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM