如何在Jade模板子块中运行脚本

How do you run scripts in Jade template sub blocks?

本文关键字:运行 脚本 Jade      更新时间:2023-09-26

我使用Jade,我有一个模板和一个内容块。我可以在模板中运行脚本,但我如何在内容块中运行脚本?

下面是一个简单的例子,mintemplate.jade:

doctype html
html
head
    script.
        alert('Layout Ready!');
body
    h1 Test
        block content

和test.jade:

extends minlayout
script.
    alert('Content Ready!');
block content
    h2 Content

'Layout Ready'警报工作正常,但'Content Ready'警报从未出现。

您需要将脚本声明移动到块定义

extends minlayout
block content
    script.
        alert('Content Ready!');
    h2 Content
模板继承