Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Installation and use of node template engine Jade

2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly explains the "node template engine Jade installation and use", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "node template engine Jade installation and use" bar!

With the development of web, the front-end application becomes more and more complex, and the back-end-based javascript (Node.js) also begins to come to the fore. At this time, javascript is expected to be greater. At the same time, the idea of javascript MVC begins to become popular. In order to separate the user interface from the business data (content), the concept of "template engine" is created.

To put it simply, a template engine is a string with several variables to be determined, and the data is dynamically stuffed into it through the template engine function.

Today we're going to talk about how to use Jade and how to use it.

Jade command line tool

The use of Jade depends on the Node environment. Install the Jade command line tool through the npm package. After the installation is successful, you can create a new file with the suffix * .jade. We can use the syntax of jade as much as we can, and after writing it, we only need to compile it through a command line tool to compile it into our usual html static file.

Installation method

1. First, determine whether the Node environment and npm tools are installed, and view them as follows:

Execute the following code in the command line tool:

Node-v = > v0.10.35npm-v = > 1.4.28 / Node environment has been successfully installed if version number information is returned successfully.

2. Install Jade command line tools globally through npm

The npm install jade-mac / mac user may require administrator privileges, using the following command sudo npm install jade-g

3. Create a * .Jade file and start the task.

4. Compile the jade file to the html file by using the Jade command line tool

How to use Jade command line tools

We can view the usage parameters of the Jade command line tool through jade-- help

Jade-- helpUsage: jade [options] [dir | file.] Options:-h,-- help output usage information / output usage information-V,-- version output the version number / output version number information-O,-- obj javascript options object / data objects transferred to the jade file-o,-- out output the compiled html to / output compiled HTML to-p,-- path filename used to resolve includes / when processing stdio Search path when looking for included files-P,-pretty compile pretty html output / formatted compiled html file-c,-client compile function for client-side runtime.js / runtime.js-n available on the compiler browser side,-- name The name of the compiled template (requires-- client) / name of the compilation template-D -- no-debug compile without debugging (smaller functions) / turn off debug options for compilation (the function will be smaller)-w -- watch watch files for changes and automatically re-render / listen for file changes and automatically refresh the compilation results-- name-after-file Name the template after the last section of the file path (requires-- client and overriden by-- name)-- doctype Specify the doctype on the command line (useful if it is not specified by the template) / specify the document type on the command line (if not specified in the template) Examples: # compile the whole A directory of $jade templates # generates {foo Bar} .html $jade {foo,bar} .jade # uses jade $jade under standard IO

< my.jade >

My.html # renders to / tmp $jade foo bar-- out / tmp using jade $echo'h 2 Jadeyards'| jade # foo, bar directory under standard IO

Example:

/ / for example, we need to compile the index.jade file, which is compiled to the html file of the same name under the same folder by default. If we want to format the output index.html file, we only need to add the-P parameter to jade-P index.jade//. If we want to achieve monitoring and automatic compilation, we need to use the-w parameter jade-P-w index.jade. Thank you for reading. These are the contents of "installation and use of node template engine Jade". After the study of this article, I believe you have a deeper understanding of the installation and use of node template engine Jade, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report