Looking at the follow code:

.wrapper
- const upName = name && name.toUpperCase();
h2
| Hello #{name.toUpperCase()}
| Welcome, #{upName}
em How are you? img.img(src="none.jpg" alt=`Dog ${age}`)

1. .wapper: div with wrapper class

div.wrapper

By defualt it consider as div class if you don't wirte div, just give a class name.

2. Define javascript variable:

    - const upName = name && name.toUpperCase();

3. Write content is different line:

    h2
| Hello #{name.toUpperCase()}
| Welcome, #{upName}

Using '|' we can write content in diffferent line, but it still display in the same line on the interface.

4. Mixin Javascript:

        | Hello #{name.toUpperCase()}
| Welcome, #{upName}

5. Attr:

img.img(src="none.jpg" alt=`Dog ${age}`)

6. Write Javascript inside attr:

alt=`Dog ${age}`

7. Define a main layout file with some 'block' placeholder:

doctype html
html
head
title= `${title} | ${h.siteName}`
link(rel='stylesheet', href='/dist/style.css')
link(rel="shortcut icon" type="image/png" href="/images/icons/doughnut.png")
meta(name="viewport" content="width=device-width, initial-scale=1")
body
block header
header.top
nav.nav
.nav__section.nav__section--pages
li.nav__item
a.nav__link.nav__link--logo(href="/")
!= h.icon('logo')
each item in h.menu
li.nav__item
a.nav__link(href=item.slug, class=(currentPath.startsWith(item.slug) ? 'nav__link--active' : ''))
!= h.icon(item.icon)
span #{item.title}
.nav__section.nav__section--search
.search
input.search__input(type="text" placeholder="Coffee, beer..." name="search")
.search__results
.nav__section.nav__section--user
if user
li.nav__item: a.nav__link(href="/hearts", class=(currentPath.startsWith('/hearts') ? 'nav__link--active' : ''))
!= h.icon('heart')
span.heart-count #{user.hearts && user.hearts.length}
li.nav__item: a.nav__link(href="/logout", class=(currentPath.startsWith('/logout') ? 'nav__link--active' : ''))
!= h.icon('logout')
span Logout
li.nav__item: a.nav__link(href="/account", class=(currentPath.startsWith('/account') ? 'nav__link--active' : ''))
img.avatar(src=user.gravatar + 'd=retro')
else
li.nav__item: a.nav__link(href="/register", class=(currentPath.startsWith('/register') ? 'nav__link--active' : '')) Register
li.nav__item: a.nav__link(href="/login", class=(currentPath.startsWith('/login') ? 'nav__link--active' : '')) Log In block messages
if locals.flashes
.inner
.flash-messages
- const categories = Object.keys(locals.flashes)
each category in categories
each message in flashes[category]
.flash(class=`flash--${category}`)
p.flash__text!= message
button.flash__remove(onClick="this.parentElement.remove()") ×
.content
block content block scripts
script(src=`https://maps.googleapis.com/maps/api/js?key=${process.env.MAP_KEY}&libraries=places`)
script(src="/dist/App.bundle.js")

Inside the layout.pug, you can see many 'block', it will use whatever you write under 'block' as default value, and later you can pass the content to replace the default value.

8. Extends main layout and override 'block':

extends layout

block content
p Hello

Now the 'block content' in layout.pug will be overrided with 'p Hello'.

[Pug] Template Engine -- Jade/ Pug的更多相关文章

  1. Vue最常用的组件通讯有三种:父->子组件通讯、子->父组件通讯,兄弟组件通讯.(template用的pug模板语法)

    Vue组件通讯   Vue最常用的组件通讯有三种:父->子组件通讯.子->父组件通讯,兄弟组件通讯.(template用的pug模板语法) 1.父->子组件通讯 父->子组件通 ...

  2. The template engine

    Play has an efficient templating system which allows to dynamically generate HTML, XML, JSON or any ...

  3. 如何选择Javascript模板引擎(javascript template engine)?

    译者 jjfat 日期:2012-9-17  来源: GBin1.com 随着前端开发的密集度越来越高,Ajax和JSON的使用越来越频繁,大家肯定免不了在前台开发中大量的使用标签,常见到的例子如下: ...

  4. [PowerShell]template engine

    今天讨论的是如何在Powershell里实现一个简单的Template Engine的功能. 假设模板文件的内容如下:template.tt hello $name welcome $company ...

  5. JFinal Template Engine 使用

    官方文档:JFinal Template Engine 文档

  6. jade(pug)学习笔记(待填充.......)

    深刻认识到总结知识点的重要性,不然遇到似曾相识的问题,要翻老半天的百度才能解决.20171018 pug——文字内部嵌入结构 比如: <a class = "href"> ...

  7. 【Reship】use of tangible T4 template engine

    1.first of all 之前在 “使用T4模板生成代码 – 初探” 文章简单的使用了T4模板的生成功能,但对于一个模板生成多个实例文件,如何实现这个方式呢?无意发现一个解决方案 “Multipl ...

  8. 最近兰州的js风格写个插件和一个template engine

    /* *@Product Name: Rational Framework Author: Calos Description: pager !important: pager */ (functio ...

  9. Js template engine

    P http://www.jquery4u.com/javascript/10-javascript-jquery-templates-engines/ http://www.creativebloq ...

随机推荐

  1. C/C++(语句,数组)

    C语言语句: 两大选择,三大循环,四大跳转 两大跳转:if,switch 三大循环:for,while,do-while 四大跳转:break,continue,goto,return do-whil ...

  2. [ReasonML] Named & optional params

    // ::country is named param // ::country=?: which make it optional // because we make ::country=? op ...

  3. PHP和JSON

    PHP和JSON 一.总结 1.php中json的使用方法:php中json的使用超级简单啦,主要是两个函数json_encode(编码)和json_decode(解码),像md5加密 2.json的 ...

  4. mysql 表设计时的update_time自动更新

    11.3.5 Automatic Initialization and Updating for TIMESTAMP and DATETIME 原文地址:https://dev.mysql.com/d ...

  5. 新手前端笔记之--初识css

    css样式表是为了容纳与html文档分离出来的样式属性而产生的,所以她理所当然的包含两个部分:1.样式的表示,使用{属性1:属性值:属性2:属性值:...},2.样式与标签的对应(如何找的对应标签), ...

  6. Codefroces Round#427 div2

    A. Key races time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

  7. nginx安装部署+增加媒体播放模块

    nginx安装很简单,但是有的时候是已经安装的nginx ,升级增加nginx 模块功能. 最近公司要nginx增加一个可以播放 MP4的模块,安装还算顺利,不说废话上命令. 1 安装依赖 yum i ...

  8. 将二级目录下的文件合并成一个文件的Python小脚本

    这个小程序的目的是将二级目录下的文件全部合并成一个文件(其实几级目录都可以,只要做少许改动) #coding:utf8 import sys, os def process(path): new_fi ...

  9. 洛谷 P1068 分数线划定

    P1068 分数线划定 题目描述 世博会志愿者的选拔工作正在 A 市如火如荼的进行.为了选拔最合适的人才,A 市对 所有报名的选手进行了笔试,笔试分数达到面试分数线的选手方可进入面试.面试分数线根 据 ...

  10. 移动mm 话费支付接入过程(ane)

    下面记录移动mm 话费支付接入的过程 1.强联网.弱联网差别.sdk是否有区分?用户体验部分由什么不同和差异? 差别在于强联网是网络通道(wifi/gprs/3g),弱联网是走短信通道,用户层面差异在 ...