[Hapi.js] View engines
View engines, or template engines, allow you to maintain a clean separation between your presentation layer and the rest of your application. This post will demonstrate how to use the vision plugin with hapi to enable template support.
server.register(require('vision'), function(){
server.views({
engines: {
hbs: require('handlebars')
},
relativeTo: __dirname,
path: 'views'
});
server.route( {
method: 'GET',
path: '/user/{username?}',
handler: function ( request, reply ) {
var username = request.params.username ? request.params.username : "World";
reply.view('home', {username: username})
}
} );
});
home.hbs:
<h1>Hello, {{username}}!</h1>
view can also support layout, to do this, we only need to add :
server.views({
engines: {
hbs: require('handlebars')
},
relativeTo: __dirname,
path: 'views',
layout: true
});
layout.hbs:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>I'm hapi!</title>
<style>
* {
font-family: 'DejaVu Sans';
font-weight: 100; color: #333;
}
h1 {
margin: 40px; padding: 50px;
text-align: center; background-color: #FA4;
box-shadow: 10px 10px 25px 0px #888;
}
</style>
</head>
<body>
{{{content}}}
</body>
</html>
It will automaticlly wrap the content into the layout.hbs.

[Hapi.js] View engines的更多相关文章
- [Hapi.js] Friendly error pages with extension events
hapi automatically responds with JSON for any error passed to a route's reply()method. But what if y ...
- js 实现angylar.js view层和model层双绑定(改变view刷新 model,改变model自动刷新view)
近段时间研究了下angular.js 觉得它内部实现的view和model层之间存在很微妙的关系,如下图 如上图说的,view的改变会update 数据层model, 数据层会update视图层vie ...
- [Hapi.js] Up and running
hapi is a rock solid server framework for Node.js. Its focus on modularity and configuration-over-co ...
- [Hapi.js] Managing State with Cookies
hapi has built-in support for parsing cookies from a request headers, and writing cookies to a respo ...
- [Hapi.js] Request Validation with Joi
hapi supports request validation out of the box using the joi module. Request path parameters, paylo ...
- [Hapi.js] Extending the request with lifecycle events
Instead of using middlware, hapi provides a number of points during the lifecycle of a request that ...
- [Hapi.js] POST and PUT request payloads
hapi makes handling POST and PUT payloads easy by buffering and parsing them automatically without r ...
- [Hapi.js] Serving static files
hapi does not support serving static files out of the box. Instead it relies on a module called Iner ...
- [Hapi.js] Replying to Requests
hapi's reply interface is one of it's most powerful features. It's smart enough to detect and serial ...
随机推荐
- 基于akka实现简单的主从框架
========================Master============================== package com.scala.akka.rpc.demo2 import ...
- Curl命令使用方法
Curl是Linux下一个很强大的http命令行工具,其功能十分强大.1) 读取网页$ curl http://www.linuxidc.com2) 保存网页$ curl http://www.lin ...
- [.NET | 發佈] 如何指定固定的目錄給程式調用的外部DLL?
1.OverView 一般程式只會查找與主程式同目錄的DLL檔案 解決方案主要可以參考這篇:http://support.microsoft.com/kb/837908 2.實作app.config方 ...
- html中行内元素与块级元素的区别。
在标准文档流里面,块级元素具有以下特点 1.总是在新行上开始,占据一整行: 2.高度,行高以及外边框和内边距都可以控制: 3.宽度始终是与游览器宽度一样,与内容无关: 4.它可以容纳内联元素和其他块级 ...
- Linq to Entities不识别方法
db.UserValidates.Include(a => a.User).Where(uv => u.UserValidates.Contains(uv, c)).ToList(); 执 ...
- (转)一小时搞定DIV+CSS布局-固定页面开度布局
本文讲解使用DIV+CSS布局最基本的内容,读完本文你讲会使用DIV+CSS进行简单的页面布局. 转载请标明:http://www.kwstu.com/ArticleView/divcss_20139 ...
- VC++ try catch (转)
VC++ try catch (转) 以前都是用try{} catch(-){}来捕获C++中一些意想不到的异常, 今天看了Winhack的帖子才知道,这种方法在VC中其实是靠不住的.例如下面的代 ...
- C# Winform中DataGridView的DataGridViewCheckBoxColumn CheckBox选中判断
1.DataGridViewCheckBoxColumn CheckBox是否选中 在判断DataGridView中CheckBox选中列的时候,用DataGridViewRow.Cells[0].F ...
- android布局常用属性记录
android布局常用属性记录 http://blog.csdn.net/xn4545945/article/details/7717086这里有一部分别人总结的其余的: align:对齐 par ...
- ECSHOP商城全站自定义TITLE标题设置
对于SEO来说,能让标题自定义的将会大大增加SEO效果,提高独立商城的流量,今天小编就收集从网上弄来ecshop全站自定义代码,很全哦! 1.Ecshop商品分类页如何实现自定义Title 最近发现很 ...