gpt4 book ai didi

node.js - 如何使用 Jade 模板将 block append 到父级

转载 作者:IT老高 更新时间:2023-10-28 23:21:33 39 4
gpt4 key购买 nike

我正在尝试使用 Jade 模板创建模块化布局。我想将一个脚本 block 从一个 child append 到它的 parent parent 中。我不太确定这是否可能。

这是我的结构

layout.jade

头 Jade

index.jade

users.jade

layout.jade: 文档类型 html#html 包括头部

    body
block content

head.jade:

head
title= title
link(rel='stylesheet', href='/stylesheets/style.css')
block scripts

index.jade:

extends layout

block content
h1 Hello

include users

users.jade

block append scripts
script(src='/javascripts/user.js')

ul
each user, i in users
li(class=i+"-"+user) #{user}

我想要的 html 输出应该是:

<!DOCTYPE html>
<html id="html">
<head>
<title>Index</title>
<link href="/stylesheets/style.css" rel="stylesheet">
<script src="/javascripts/user.js"> <!--// append this from user.jade into head.jade //-->
</head>
<body>

<h1>Hello bob</h1>
<li class="0-user1">user1</li>

最佳答案

这应该是可以的,还有examples in the jade documentation正是这样做的。你的代码看起来都很好,除了你需要在 users.jade 中缩进你的 script 标签,所以它在 block append script 指令下面缩进。

关于node.js - 如何使用 Jade 模板将 block append 到父级,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13551387/

39 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com