gpt4 book ai didi

html - 使用 Hogan.js 进行部分处理

转载 作者:太空宇宙 更新时间:2023-11-04 00:55:37 25 4
gpt4 key购买 nike

首先我想说我是 Node.js 新手。

<小时/>

我的问题是这样的。有没有一种方法可以将单一布局用于 HTML?分别类似于 MCV 和 ASP 中的共享 View 主布局

例如:

//。 hello_world.hjs

<!DOCTYPE html>
<html>
<head>
<title>{{ title }}</title>
<link rel='stylesheet' href='/stylesheets/style.css' />
</head>
<body>
<h1>{{ title }}</h1>
<div id="content">
<!-- Place changing page content here -->
{{> part }}
</div>
<footer>
{{date}}
</footer>
</body>
</html>

//。 hello_world.js

var express = require('express');
var router = express.Router();

/* GET home page. */
router.get('/', function(req, res, next) {
res.render('hello_world', {
title: 'Hello World!',
partials: {
part: 'part'
}
});
});

//。部分.html

<h1>This is a part</h1>

我只想更改hello_world.hjs中id为“content”的div中的内容这样,当对页脚或导航栏进行更新时,不必进行更改对每个文档进行处理。

<小时/>

文件夹结构->

routes
-- hello_world.js

views
--hello_world.hjs
--part.html
--index.hjs
<小时/>

我尝试寻找解决方案。但是,我不确定我在搜索中是否使用了正确的术语。

最佳答案

part.html 必须重命名为part.hjs。然而,这仍然没有回答整个问题。虽然我现在能够使用部分,但我需要能够使用一致的布局,并且我希望不必在 JS 文件中重复自己,例如:

partials: { 
part: 'part',
footer: 'footer'
}

在大型网站上重新输入这些内容会变得过时并且容易出现拼写错误。

关于html - 使用 Hogan.js 进行部分处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30006860/

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