【发布时间】:2021-09-24 11:13:54
【问题描述】:
Pug 文档说它可以变形
doctype html
html(lang="en")
head
title= pageTitle
script(type='text/javascript').
if (foo) bar(1 + 5)
body
h1 Pug - node template engine
#container.col
if youAreUsingPug
p You are amazing
else
p Get on it!
p.
Pug is a terse and simple templating language with a
strong focus on performance and powerful features.
到
<!DOCTYPE html>
<html lang="en">
<head>
<title>Pug</title>
<script type="text/javascript">
if (foo) bar(1 + 5)
</script>
</head>
<body>
<h1>Pug - node template engine</h1>
<div id="container" class="col">
<p>You are amazing</p>
<p>Pug is a terse and simple templating language with a strong focus on performance and powerful features.</p>
</div>
</body>
</html>
但请注意,在生成的 HTML 中,其中有一个脚本文件。那不是我想要的。我不能生成 HTML 结果以便脚本也被评估吗? 例如,如果里面有 DOM 操作逻辑,结果 HTML 应该反映它而不是显示脚本标签。
【问题讨论】:
-
Pugjs 能够有条件地渲染输出 HTML pugjs.org/language/conditionals.html
-
@ross-u nope,因为 OP 说他想在 HTML 中评估 JS 并获得没有脚本标签的最终 HTML,你的链接在 HTML 中仍然有脚本标签
标签: javascript node.js pug