java 模板继承,Pug模板继承与拓展

Pug 支持使用 block 和 extends 关键字进行模板的继承

block代表一个代码块

一、代码块的替换

如下:便有三个代码块block scripts,block content,block foot

//- layout.pug

html

head

title 我的站点 - #{title}

block scripts

script(src='/jquery.js')

body

block content

block foot

#footer

p 一些页脚的内容

如替换其中的代码块

在一个新的pug文件中 ,首先要用extends继承某个pug, 然后定义相同名称的代码块即可实现替换

extends layout.pug

block scripts

script(src='/jquery.js')

script(src='/pets.js')

block content

h1= title

- var pets = ['猫', '狗']

each petName in pets

include pet.pug

在覆盖一个代码块的同时在该代码块内添加新的代码块

//- sub-layout.pug

extends layout.pug

//- 覆盖原有的content代码块,并添加了两个子代码块 sidebar primary

block content

.sidebar

block sidebar

p 什么都没有

.primary

block primary

p 什么都没有

二、块内容的添补 append / prepend

prepend(向头部添加内容),或者 append(向尾部添加内容)一个块。

下面代码实现了在 代码块head里面添加了两个script

//- page.pug

extends layout.pug

block append head

script(src='/vendor/three.js')

script(src='/game.js')

b739ec46bb5c46d9c0aa4ce35ba1ea56.png

关于找一找教程网

本站文章仅代表作者观点,不代表本站立场,所有文章非营利性免费分享。

本站提供了软件编程、网站开发技术、服务器运维、人工智能等等IT技术文章,希望广大程序员努力学习,让我们用科技改变世界。

[Pug模板继承与拓展]http://www.zyiz.net/tech/detail-130331.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Pug是一种模板引擎,可用于生成HTML。您可以使用Pug轻松地创建登录注册页面。以下是一个示例代码: ``` doctype html html(lang="en") head title Login/Register Page style. body { background-color: #f2f2f2; font-family: Arial, Helvetica, sans-serif; } .container { background-color: #fff; width: 500px; margin: 0 auto; padding: 20px; border-radius: 5px; box-shadow: 0px 0px 10px rgba(0,0,0,0.2); } h1 { text-align: center; margin-bottom: 30px; } input[type=text], input[type=password] { width: 100%; padding: 12px 20px; margin: 8px 0; display: inline-block; border: 1px solid #ccc; border-radius: 4px; box-sizing: border-box; } button { background-color: #4CAF50; color: white; padding: 14px 20px; margin: 8px 0; border: none; border-radius: 4px; cursor: pointer; } button:hover { background-color: #45a049; } body .container h1 Login/Register form(action="/login" method="post") label(for="username") Username input(type="text" placeholder="Enter Username" name="username" required) label(for="password") Password input(type="password" placeholder="Enter Password" name="password" required) button(type="submit") Login form(action="/register" method="post") label(for="username") Username input(type="text" placeholder="Enter Username" name="username" required) label(for="password") Password input(type="password" placeholder="Enter Password" name="password" required) label(for="password") Confirm Password input(type="password" placeholder="Confirm Password" name="confirm_password" required) button(type="submit") Register ``` 这段代码使用Pug语法构建了一个登录注册页面。其中,使用了HTML元素和Pug独有的缩进语法。在这个示例中,我们使用了两个表单来实现登录和注册功能。在每个表单中,我们使用了`label`元素和`input`元素来实现表单输入。我们还使用了CSS样式来美化页面。 如果您有任何问题或需要更多帮助,请告诉我。我会尽力回答您的问题。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值