【问题标题】:How to make a pug template render inside of Webtask.io Node/Express serverless app?如何在 Webtask.io Node/Express 无服务器应用程序中制作 pug 模板呈现?
【发布时间】:2019-03-10 08:52:17
【问题描述】:

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

'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"

我已将 Pug 注册为 express 应用程序的视图引擎,但是,似乎 Pug 没有被调用。我错过了什么?如何注册 Pug 以便它在 Webtask.io Node 应用程序中呈现模板?

我找不到任何使用 Pug 执行此操作的示例,但是,我找到了 post saying it's possible。这篇文章讨论了 Webtask 编译器。我找不到你如何让 Pug 成为编译器。

我没有和帕格结婚。是否有更好的选择来从适用于 Webtask 方法的模板中呈现动态 HTML?我在 Google 上搜索了 Handlebars,但找不到示例。

感谢您的宝贵时间。

【问题讨论】:

    标签: pug auth0 webtask


    【解决方案1】:

    Pug 使用两个空格的缩进标准。这绝对是您看到的哈巴狗格式错误,因此已正确连接。

    试试这个模板:

    #message
      h1 Hello World Foo
      h2 pug's in the house
    

    【讨论】:

    • 非常感谢。我不知道两行间距规则。感谢您的时间和帮助。
    猜你喜欢
    • 2013-04-17
    • 2017-04-24
    • 1970-01-01
    • 1970-01-01
    • 2017-10-13
    • 2012-12-04
    • 1970-01-01
    • 2018-05-19
    • 1970-01-01
    相关资源
    最近更新 更多