PUG转换为EJS?

时间:2018-03-31 14:53:19

标签: pug ejs

我试图在.ejs中转换以下.PUG但是无法弄明白。有人可以帮忙吗?

就个人而言,我对PUG很可怕

var http = require('http'),
        path = require('path'),
        express = require('express'),
        app = express(),
        server = http.createServer(app),
        socketIO = require('socket.io'),
        port = process.env.PORT || 8080,
        history = require('connect-history-api-fallback'),
        serveStatic = require('serve-static')


app.use(serveStatic(path.join(__dirname, '/dist')))

server.listen(port, () => {
    // logs when running node server.js
    console.log('listening on port', port)
})

const io = socketIO(server);

io.on('connection', (socket) => {
  console.log('Connected!!!');
});

1 个答案:

答案 0 :(得分:0)

无法将整个模板转换为EJS,因为EJS不支持Pug的布局和布局继承概念:EJS中不存在extendsblock 。解释了另一种解决方案in EJS's README:您可以为页眉和页脚创建两个单独的模板,并在主模板的顶部和底部创建include个模板。

关于模板的其余部分,这里是EJS:

<h1><%= title %></h1>
<ul>
  <% articles.forEach(function(article) { %>
    <li><%= article.title %></li>
  <% }); %>
</ul>