express中的handlebars的段落使用
1、创建帮助器。
var handlesbars = require("express-handlebars").create({
    defautLayout:"main",
    helpers:{
        section:function(name,options){
            if(!this._sections)
                this._sections={};
            this._sections[name] = options.fn(this);
            return null;
        }
    }
});
2、在布局(母版页)中声明一个占位。
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>bookstore</title>
    {{{_sections.head}}}
</head>
<body>
    {{{body}}}
</body>
</html>
3、在视图中创建段落。
{{#section "head"}}
    <style>
        *{
            color:blue;
        }
    </style>
{{/section}}
<h1>主页</h1>
 
                    
                     
                    
                 
                    
                 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号