Looking at the follow code:

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

1. .wapper: div with wrapper class

  1. div.wrapper

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

2. Define javascript variable:

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

3. Write content is different line:

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

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

4. Mixin Javascript:

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

5. Attr:

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

6. Write Javascript inside attr:

  1. alt=`Dog ${age}`

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

  1. doctype html
  2. html
  3. head
  4. title= `${title} | ${h.siteName}`
  5. link(rel='stylesheet', href='/dist/style.css')
  6. link(rel="shortcut icon" type="image/png" href="/images/icons/doughnut.png")
  7. meta(name="viewport" content="width=device-width, initial-scale=1")
  8. body
  9. block header
  10. header.top
  11. nav.nav
  12. .nav__section.nav__section--pages
  13. li.nav__item
  14. a.nav__link.nav__link--logo(href="/")
  15. != h.icon('logo')
  16. each item in h.menu
  17. li.nav__item
  18. a.nav__link(href=item.slug, class=(currentPath.startsWith(item.slug) ? 'nav__link--active' : ''))
  19. != h.icon(item.icon)
  20. span #{item.title}
  21. .nav__section.nav__section--search
  22. .search
  23. input.search__input(type="text" placeholder="Coffee, beer..." name="search")
  24. .search__results
  25. .nav__section.nav__section--user
  26. if user
  27. li.nav__item: a.nav__link(href="/hearts", class=(currentPath.startsWith('/hearts') ? 'nav__link--active' : ''))
  28. != h.icon('heart')
  29. span.heart-count #{user.hearts && user.hearts.length}
  30. li.nav__item: a.nav__link(href="/logout", class=(currentPath.startsWith('/logout') ? 'nav__link--active' : ''))
  31. != h.icon('logout')
  32. span Logout
  33. li.nav__item: a.nav__link(href="/account", class=(currentPath.startsWith('/account') ? 'nav__link--active' : ''))
  34. img.avatar(src=user.gravatar + 'd=retro')
  35. else
  36. li.nav__item: a.nav__link(href="/register", class=(currentPath.startsWith('/register') ? 'nav__link--active' : '')) Register
  37. li.nav__item: a.nav__link(href="/login", class=(currentPath.startsWith('/login') ? 'nav__link--active' : '')) Log In
  38.  
  39. block messages
  40. if locals.flashes
  41. .inner
  42. .flash-messages
  43. - const categories = Object.keys(locals.flashes)
  44. each category in categories
  45. each message in flashes[category]
  46. .flash(class=`flash--${category}`)
  47. p.flash__text!= message
  48. button.flash__remove(onClick="this.parentElement.remove()") ×
  49. .content
  50. block content
  51.  
  52. block scripts
  53. script(src=`https://maps.googleapis.com/maps/api/js?key=${process.env.MAP_KEY}&libraries=places`)
  54. 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':

  1. extends layout
  2.  
  3. block content
  4. 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. ifup&&ifdown --- 激活/关闭指定的网络接口。

    ifup命令用于激活指定的网络接口. ifup eth0 #激活eth0 ifdown命令用于禁用指定的网络接口. ifdown eth0 #禁用eth0

  2. pip 更新安装失败解决方法

    python3 -m ensurepip https://stackoverflow.com/questions/28664082/python-no-module-pip-main-error-wh ...

  3. 【Pycharm】【HTML/jQuery】代码换行问题

    问题:从网上下载jQuery文件后发现代码太长,不利于阅读:Pycharm没有预先设置好js文件的自动换行设置 问题 解决办法 解决后

  4. 【Codeforces Round #426 (Div. 2) A】The Useless Toy

    [Link]:http://codeforces.com/contest/834/problem/A [Description] [Solution] 开个大小为4的常量字符数组; +n然后余4,-n ...

  5. 洛谷——T1725 探险

    http://codevs.cn/problem/1725/ 时间限制: 1 s  空间限制: 256000 KB 题目等级 : 钻石 Diamond 题解  查看运行结果   题目描述 Descri ...

  6. theme-不同主题资源更改

    1.找到了影响桌面小部件的布局文件packages/apps/Mms$ vim res/layout/widget.xml修改里面的背景颜色属性,可以实现预期效果,至于里面的 <LinearLa ...

  7. Filebeat之input和output(包含Elasticsearch Output 、Logstash Output、 Redis Output、 File Output和 Console Output)

    前提博客 https://i.cnblogs.com/posts?categoryid=972313 Filebeat啊,根据input来监控数据,根据output来使用数据!!! Filebeat的 ...

  8. Vue 学习记录<1>

    1.环境搭建:(前提node.js搭建) # 全局安装 vue-cli $ npm install --global vue-cli   # 创建一个基于 webpack 模板的新项目 $ vue i ...

  9. 25.Spring @Transactional工作原理

    转自:http://www.importnew.com/12300.html 本文将深入研究Spring的事务管理.主要介绍@Transactional在底层是如何工作的.之后的文章将介绍: prop ...

  10. PatentTips - Resource partitioning and direct access utilizing hardware support for virtualization

    BACKGROUND The present disclosure relates to the resource management of virtual machine(s) using har ...