Home Web Front-end JS Tutorial How to use node front-end template engine Jade tag

How to use node front-end template engine Jade tag

May 30, 2018 am 11:10 AM
node front end template

This time I will show you how to use the node front-endtemplate engineJade tag, and use nodefront-end templateengine Jade tagWhat are the precautionsWhat are the following? This is a practical case, let’s take a look at it.

1. Document declaration

#When we start writing an html page, we must first write the DOCTYPE document declaration. Now it is usually the case Next we all use the HTML5 document declaration method, so how should we write it in jade?

There are two ways to write document declarations in jade:

  1. We can write doctype html directly in the jade file

  2. jade provides us with a simple writing method, (but it seems that jade does not recommend this method in the new version after the upgrade -_-||| )

Of course , jade also supports other types of document declarations by default, just use doctype to follow the following options. By default, jade supports:

var doctypes = exports.doctypes = {
 '5': '<!DOCTYPE html>',
 'xml': '<?xml version="1.0" encoding="utf-8" ?>',
 'default': '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">',
 'transitional': '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">',
 'strict': '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">',
 'frameset': '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">',
 '1.1': '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">',
 'basic': '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.1//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic11.dtd">',
 'mobile': '<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.2//EN" "http://www.openmobilealliance.org/tech/DTD/xhtml-mobile12.dtd">'
};
Copy after login

doctype is not case-sensitive, so the following two have the same effect:

doctype Default
doctype default
Copy after login

For example: if we want to write an XHTML 1.0 Strict document declaration , you can write like this:

doctype strict
Copy after login

The compilation result is as follows:

Copy code The code is as follows:

##2、 Tag

The tag in jade is written very simply, it is just one word.

doctype html
html
 head
 title
 body
Copy after login
The above code will be compiled into:

<!DOCTYPE html>
<html>
 <head>
 <title></title>
 </head>
 <body></body>
</html>
Copy after login
jade uses strict indentation to distinguish the beginning and end of tags. The default is 2 spaces to indicate indentation.

If we want to write a label with content, for example, if we want to write a title, we only need to add a space after the label word, and then follow the content.

h1 this is a title.
p this is a paragraph.
Copy after login
The compilation result is:

this is a title.

this is a paragraph.

Sometimes, we will need to output some text in a special format or to improve the readability of the code, we need to display the following effect:

< ;p>

1. 001
2. 002
3. 003
4. 004


Then what we should do in jade How to write it? Here jade provides us with two methods. The first is to add a | and a space in front of each line:

p
 | 1. 001
 | 2. 002
 | 3. 003
 | 4. 004
Copy after login
The second method is: follow the label name with a . Number. Then the content under this tag will be parsed into a code segment by jade:

p.
 1. 001
 2. 002
 3. 003
 4. 004
Copy after login
Now some students are confused and confused. What is the difference between the two methods? Here we have to talk about tag mixing. If we have such a requirement, we need to add a strong tag after 1 in the above code.

First of all, let’s talk about the first case, our writing method:

p
 | 1. 001
 strong aaa
 | 2. 002
 | 3. 003
 | 4. 004
Copy after login
If it is the second writing method, we need to write it like this:

p.
 1. 001
 <strong>aaa</strong>
 2. 002
 3. 003
 4. 004
Copy after login
The compilation result is as follows :

1. 001
aaa
2. 002
3. 003
4. 004


##3. Tag’s attribute and attribute value##h1 p and other tags, we usually write id & class attributes for them, so how should this be written in jade? The same syntax as zen coding, we only need to write like this:

h1#id.class this is a title.
p#j-text.text this is a paragraph.
Copy after login
The compilation result is:

this is a title.

this is a paragraph.

等等,那我要是想添加多个 class 怎么办呢?这样办:

h1#id.class1.class2.class3 this is a title.
p#j-text.text this is a paragraph.
Copy after login

编译结果为:

this is a title.


this is a paragraph.

什么?写 p 写烦了?那就不写咯。

#id.class
#id.class1.class2 this is a p without tags.
Copy after login

编译结果为:


this is a p without tags.

这里要说明一下,在 jade 的语法里面,只有 p 标签能够省略不写.

说完了 id 和 class,我们再来说一下标签其他的属性应该怎么添加。jade 里添加其他属性和值的语法也和 zen coding 类似,我们需要在标签后面加上小括号(),然后按照(属性名=属性值)的格式写就好了,如果有多个属性,中间以逗号进行分割。

比如上面的 id 和 class 的写法我们就可以改写成:

h1(id="id", class="class") this is a title.
p(id="j-text", class="text") this is a paragraph.
Copy after login

结果是一样的:

this is a title.


this is a paragraph.

说来说去还是这两个属性,烦了?那我们换一个吧:

a(herf="/index.html", title="this is a link.", target="_blank", data-uid="1000") index.html
Copy after login

编译结果为:

index.html

那么问题就来了,如果我们要写一个单属性应该怎么写?比如给表单元素添加 checked属性:

input(type="checkbox", name="all", checked, value="全选")
Copy after login

编译结果为:

相信看了本文案例你已经掌握了方法,更多精彩请关注php中文网其它相关文章!

推荐阅读:

如何操作nodeJS服务器创建与重启

怎样进行Vue拖拽组件开发

The above is the detailed content of How to use node front-end template engine Jade tag. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Clair Obscur: Expedition 33 - How To Get Perfect Chroma Catalysts
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1677
14
PHP Tutorial
1278
29
C# Tutorial
1257
24
Pi Node Teaching: What is a Pi Node? How to install and set up Pi Node? Pi Node Teaching: What is a Pi Node? How to install and set up Pi Node? Mar 05, 2025 pm 05:57 PM

Detailed explanation and installation guide for PiNetwork nodes This article will introduce the PiNetwork ecosystem in detail - Pi nodes, a key role in the PiNetwork ecosystem, and provide complete steps for installation and configuration. After the launch of the PiNetwork blockchain test network, Pi nodes have become an important part of many pioneers actively participating in the testing, preparing for the upcoming main network release. If you don’t know PiNetwork yet, please refer to what is Picoin? What is the price for listing? Pi usage, mining and security analysis. What is PiNetwork? The PiNetwork project started in 2019 and owns its exclusive cryptocurrency Pi Coin. The project aims to create a one that everyone can participate

PHP and Vue: a perfect pairing of front-end development tools PHP and Vue: a perfect pairing of front-end development tools Mar 16, 2024 pm 12:09 PM

PHP and Vue: a perfect pairing of front-end development tools. In today's era of rapid development of the Internet, front-end development has become increasingly important. As users have higher and higher requirements for the experience of websites and applications, front-end developers need to use more efficient and flexible tools to create responsive and interactive interfaces. As two important technologies in the field of front-end development, PHP and Vue.js can be regarded as perfect tools when paired together. This article will explore the combination of PHP and Vue, as well as detailed code examples to help readers better understand and apply these two

Is Django front-end or back-end? check it out! Is Django front-end or back-end? check it out! Jan 19, 2024 am 08:37 AM

Django is a web application framework written in Python that emphasizes rapid development and clean methods. Although Django is a web framework, to answer the question whether Django is a front-end or a back-end, you need to have a deep understanding of the concepts of front-end and back-end. The front end refers to the interface that users directly interact with, and the back end refers to server-side programs. They interact with data through the HTTP protocol. When the front-end and back-end are separated, the front-end and back-end programs can be developed independently to implement business logic and interactive effects respectively, and data exchange.

Exploring Go language front-end technology: a new vision for front-end development Exploring Go language front-end technology: a new vision for front-end development Mar 28, 2024 pm 01:06 PM

As a fast and efficient programming language, Go language is widely popular in the field of back-end development. However, few people associate Go language with front-end development. In fact, using Go language for front-end development can not only improve efficiency, but also bring new horizons to developers. This article will explore the possibility of using the Go language for front-end development and provide specific code examples to help readers better understand this area. In traditional front-end development, JavaScript, HTML, and CSS are often used to build user interfaces

C# development experience sharing: front-end and back-end collaborative development skills C# development experience sharing: front-end and back-end collaborative development skills Nov 23, 2023 am 10:13 AM

As a C# developer, our development work usually includes front-end and back-end development. As technology develops and the complexity of projects increases, the collaborative development of front-end and back-end has become more and more important and complex. This article will share some front-end and back-end collaborative development techniques to help C# developers complete development work more efficiently. After determining the interface specifications, collaborative development of the front-end and back-end is inseparable from the interaction of API interfaces. To ensure the smooth progress of front-end and back-end collaborative development, the most important thing is to define good interface specifications. Interface specification involves the name of the interface

How to add PPT mask How to add PPT mask Mar 20, 2024 pm 12:28 PM

Regarding PPT masking, many people must be unfamiliar with it. Most people do not understand it thoroughly when making PPT, but just make it up to make what they like. Therefore, many people do not know what PPT masking means, nor do they understand it. I know what this mask does, and I don’t even know that it can make the picture less monotonous. Friends who want to learn, come and learn, and add some PPT masks to your PPT pictures. Make it less monotonous. So, how to add a PPT mask? Please read below. 1. First we open PPT, select a blank picture, then right-click [Set Background Format] and select a solid color. 2. Click [Insert], word art, enter the word 3. Click [Insert], click [Shape]

Django: A magical framework that can handle both front-end and back-end development! Django: A magical framework that can handle both front-end and back-end development! Jan 19, 2024 am 08:52 AM

Django: A magical framework that can handle both front-end and back-end development! Django is an efficient and scalable web application framework. It is able to support multiple web development models, including MVC and MTV, and can easily develop high-quality web applications. Django not only supports back-end development, but can also quickly build front-end interfaces and achieve flexible view display through template language. Django combines front-end development and back-end development into a seamless integration, so developers don’t have to specialize in learning

Questions frequently asked by front-end interviewers Questions frequently asked by front-end interviewers Mar 19, 2024 pm 02:24 PM

In front-end development interviews, common questions cover a wide range of topics, including HTML/CSS basics, JavaScript basics, frameworks and libraries, project experience, algorithms and data structures, performance optimization, cross-domain requests, front-end engineering, design patterns, and new technologies and trends. . Interviewer questions are designed to assess the candidate's technical skills, project experience, and understanding of industry trends. Therefore, candidates should be fully prepared in these areas to demonstrate their abilities and expertise.

See all articles