代码之家  ›  专栏  ›  技术社区  ›  Tom Schreck

如何在Webtask.io Node/Express serverless应用程序中呈现一个pug模板?

  •  1
  • Tom Schreck  · 技术社区  · 7 年前

    我正在尝试从Webtask.io无服务器节点应用程序中的路由呈现一个非常简单的帕格模板。以下是我的尝试:

    'use latest';
    import express from 'express';
    import pug from 'pug'
    
    const app = express();    
    app.set('view engine', 'pug');
    ...
    
      app.get('/', (req, res) =>
      {
        var page = `
        #message
            h1 Hello World Foo
            h2 pug's in the house`;
    
        const HTML = pug.render(page);
    
        res.status(200).send(HTML)
      });
    
    ...
    module.exports = fromExpress(app);
    

    我收到的错误是:

    Error: Pug:2:1
        1|
      > 2|     #message
    -------^
        3|         h1 Hello World Foo
        4|         h2 pug's in the house
    
    unexpected token "indent"
    

    post saying it's possible

    我没和帕格结婚。有没有更好的方法来从模板中呈现动态HTML,这些模板将使用Webtask方法?我在谷歌上搜索过车把,却找不到一个例子。

    1 回复  |  直到 7 年前
        1
  •  1
  •   Graham francescalus    7 年前

    帕格使用两个空间的缩进标准。这绝对是一个帕格格式的错误,你看到这样的连接正确。

    请改用此模板:

    #message
      h1 Hello World Foo
      h2 pug's in the house
    
    推荐文章