Skip to Content
Node与Express开发(第2版)
book

Node与Express开发(第2版)

by Ethan Brown
June 2021
Intermediate to advanced
290 pages
9h 21m
Chinese
Posts & Telecom Press
Content preview from Node与Express开发(第2版)
视图模板——使用
Handlebars
|
77
犹不及。在跨浏览器兼容性和合法
HTML
方面,模板也是你的第一道防线。这些模板应该
由精通前端开发的人员细心地编写和维护。一个很好的入手点(尤其对新手来说)是使用
HTML5
样板
。在前面的示例中,为适合排版,我们一直都是使用最小化的
HTML5
模板,
但对于实际的项目,则会使用
HTML5
样板。
另一个入手点就是第三方主题,很多人会采用这种方式。像
Themeforest
和
W
rapBootstrap
这样的网站有数百个直接可用的
HTML5
主题
,你可以把它们当作模板起点。使用第三方
主题,先要采纳它的主文件(通常是
index.html
)
,把它重命名为
main.hanidlebars
(或者自
定义的布局文件名),把所有资源文件(
CSS
、
Javascript
、图片)放入用以存放静态文件的
public
目录。然后必须编辑这个模板文件,并确定要把
{{{body}}}
表达式放到哪里。
你可能想把一部分模板中的元素移入
partial
模
板。
主页横幅
(一种高高的横幅广告,用
来抓住用户的眼球)就是一个很好的例子。如果这个主页横幅需要在每一页出现(可能不
是个好的选择),就让它留在模板文件里;如果只在某一页出现(通常是主页),那就把它
放在对应的视图里;如果需要在好几页(但不是全部)出现,则可以考虑把它放进一个
partial
里。如何选择你自己决定,而这正是打造一个独特而吸引人的网站的艺术。
7.5
 小结
我们已经看到模板化是如何使得代码更易写、易读、易维护的。多亏了模板,我们才不需
要痛苦地在 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

面向对象的思考过程(原书第5版)

面向对象的思考过程(原书第5版)

马特 魏斯费尔德
精通模块化JavaScript

精通模块化JavaScript

Nicolás Bevacqua
前端架构设计

前端架构设计

Micah Godbolt

Publisher Resources

ISBN: 9787115565099