Skip to content

Instantly share code, notes, and snippets.

@jinlong
Last active September 22, 2016 09:50
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jinlong/8297190 to your computer and use it in GitHub Desktop.
Save jinlong/8297190 to your computer and use it in GitHub Desktop.
Express blog demo.
<h1>{{blog.title}}</h1>
Published: {{blog.published}}
<p/>
{{blog.body}}
<h1>Blog!</h1>
{{#each entries}}
<p>
<a href="/article/{{id}}">{{title}}</a><br/>
Published: {{published}}
</p>
{{/each}}
<html>
<head>
<title>Home Page</title>
</head>
<body>
<h1>Blog!</h1>
<footer>
<p>
<a href="/">Home</a> ~ <a href="/about">About Me</a> ~ <a href="/article">Some Article</a>
</p>
</footer>
</body>
</html>
<html>
<head>
<title>{{title}}</title>
</head>
<body>
{{{body}}}
<footer>
<p>
<a href="/">Home</a> ~ <a href="/about">About Me</a>
</p>
</footer>
</body>
</html>
<link href="/bootstrap/css/bootstrap.css" rel="stylesheet">
@Ming-Zhe
Copy link

有些疑问

  • layout.html 里的 {{{body}}} 是怎么自动从home-tpl.html引入内容过来。
  • article.html 怎么自动添加 <head> <footer> 等partial。

求指教~~

@jinlong
Copy link
Author

jinlong commented Feb 19, 2014

layout.html 是html 通用的文件模板,其它的 html 可能就 {{title}} 和 {{{body}}} 发生变化,不同的 title 和 body 在res.render 的时候传入:
例如:res.render('index',{title:"My Blog", entries:blogEngine.getBlogEntries()});

@jinlong
Copy link
Author

jinlong commented Feb 19, 2014

article.html 和 home.html 都会套用 layout.html 模板

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment