您好,我正在尝试使用 Jade 的 block 和 延长 对于 node.js 项目,ideia 是这样的:
布局.jade:
head
script
$(document).ready(function() {
block js_doc_ready
//here goes the doc ready
});
index.jade:
block js_doc_ready
alert('hello!');
alert('one more js line code');
alert('end my js doc ready for this view');
这会给我一个 index.html 像这样:
...
<head>
<script type="text/javascript">
$(document).ready(function() {
alert('hello!');
alert('one more js line code');
alert('end my js doc ready for this view');
});
</script>
</head>
...
但是当我看到结果时, '阻止 js_doc_ready' 不被视为 Jade block 。
此外,即使它被视为一个 block , “警报('你好!);' 不会被视为 Jade 标签,而是 Jade 标签。
这是我以前在 django 模板中做的事情,但是在带有所有这些标签的 Jade 中,并且没有自由做纯 html 我仍然觉得做这些事情有点太奇怪了。
最佳答案
Jade 不翻译“样式”和“脚本”代码中的内容。绝不。
什么会起作用取决于我给出的答案 to another question (使用样式元素,但基本相同)。
!!!
head
title Hello jade
| <script type='text/javascript'>
| $(document).ready(function() {
block js_doc_ready
| });
| </script>
这样:jade 将包含 HTML 'script' 标签和 $.ready 行,但也会包含您的 block 。
关于templates - Jade - 在脚本标签内使用 block ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10965406/