[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 ...
 
随机推荐
- [RxJS] Combining Streams with CombineLatest
			
Two streams often need to work together to produce the values you’ll need. This lesson shows how to ...
 - asp.net cookie和session的详细使用
			
cookie使用代码: //设置Cookie HttpCookie setCookie = new HttpCookie("test"); setCookie.Values.Add ...
 - 关于sys、system、sysman等在EM中登录的问题
			
1.sysman要先在SQL*Plus上解锁: (1)以"sysdba"的身份登录 conn system/密码 as sysdba; (2)解锁 alter user sysma ...
 - CentOS 恢复 rm -rf * 误删数据(转)
			
一. 将磁盘分区挂载为只读 这一步很重要,并且在误删除文件后应尽快将磁盘挂载为只读.越早进行,恢复的成功机率就越大. 1. 查看被删除文件位于哪个分区 [root@localhost ~]# mo ...
 - C++类中的静态成员变量与静态成员函数的使用
			
代码: #include <iostream> #include <string> #include <cstdio> using namespace std; c ...
 - php统计文件夹大小
			
function dirsize($dir){ @$dh = opendir($dir); $size = 0; while($file = @readdir($dh)){ if($file!=&qu ...
 - 阿里云Centos7使用yum安装MySQL5.6的正确姿势
			
阿里云Centos7使用yum安装MySQL5.6 阿里云Centos7使用yum安装MySQL5.6 前言:由于某些不可抗力,我要在自己的阿里云服务器上搭建hadoop+hive+mysql+tom ...
 - Yum中实现与apt-get install build-essential功能类似的命令
			
在Ubuntu中安装完系统后,可以直接使用apt-get install build-essential命令安装常用的开发编译工具包.在诸如CentOS这样的使用Yum包管理的系统中,其实也有类似的实 ...
 - debian系统下安装ssh服务
			
它是什么?? SSH 为 Secure Shell 的缩写,简单地说,SSH 为建立在应用层基础上的安全协议.SSH 是目前较可靠,专为远程登录会话和其他网络服务提供安全性的协议.利用 SSH 协议可 ...
 - Dijkstra算法C#实现及其布线运用
			
大家好,我是小鸭酱,博客地址为:http://www.cnblogs.com/xiaoyajiang 以下是空调布线对Dijkstra算法的运用,采用C#实现. 问题:室内机多台,室外机一台.寻找室内 ...