Recently learning to use node's Express framework to build a Web site that involves view rendering. This can be aided by the template engine Ejs or jade (the template engine has many, the most used, the more perfect is Ejs and Jade).
Is it better to choose which template engine? Online also have a lot of argument, I also surf the internet to see a bit, basically is "one-sided", but finally I still can not draw from the net which template engine use is better. Ejs syntax and general PHP, JSP is similar, is the use of <% code%> This angle bracket percent inclusion content way, look not difficult, the cost of learning is not too high, but I think the disadvantage is too much to use <%%> This way to nest will be easy to confuse the feeling accidentally write wrong, want to find a problem may also be more troublesome. And Jade's syntax is similar to zen-coding (about zen-coding syntax you can search the information online, here is not described in detail, Zen-coding is said to be the former name, and now some people called Emmet, in Sublime Text installation of the package will be very convenient for normal coding, personal think it is closer to people's thinking, it is in accordance with the logic of a layer down to write code, there will be a kind of training the logic of the bright bird ~ But Jade's study cost is relatively high, preferably the first zen-coding of the grammatical basis, It's a lot easier to learn jade in this way. Some of the early node tutorials on the Internet have dropped to the template engine section, mostly using Ejs to explain, which can reduce the difficulty of learning, suitable for beginners.
But in the end I chose Jade when I was doing the project because of the foundation of Zen-coding and the challenge of learning a new language when I was doing the project.
Provide a jade learning site: http://segmentfault.com/a/1190000000357534
Since personal comparison is used sublime text to encode, it is recommended to learn jade when it is best to install a jade-related plug-in, Https://packagecontrol.io/search/jade here are some in sublime The text can be installed in the Jade plug-in, according to the name in the package install on the OK Bird ~
Jade will make the jade file syntax highlighted under the sublime text editor;
Jade build is said to hold ctrl+b can be the jade file compiled into an HTML file, the output of the HTML file in the same directory, but I tried to fail to output ~;
Jadesnippets can also be a good way to help with the writing speed of Jade (this plugin is good);
I want to install is the Html2jade plug-in, the plug-in is to automatically convert the HTML file into the jade format of the file, but I did not search the package install the plugin, let alone installed. Here's an online conversion URL: http://html2jade.aaron-powell.com/feels good to use.
I didn't install the other Jade plugins, but you can try their functions.
Now let's talk about some jade tricks:
In Jade to be very careful of the space, because Jade is to use a space to control the nesting relationship of elements, sometimes more than one space or a space will be wrong, the most common mistake is in the node console or according to the route in the browser to open the page, will prompt "indent" indentation problem, Causes the page to fail to display. It is recommended to either use tab, or use the keyboard's SPACEBAR to control, do not mix, or increase the chance of error. It is also mentioned on the Internet that Jade uses 2 spaces to control indentation instead of 4 spaces, which can be solved when you encounter a similar problem.
In addition, if you can only render the template file (that is, the common elements), the sub-content part of the rendering is not possible, you might want to see whether the extends layout and block content added blank lines or spaces, to remove it.
Author: Zhi Zhi
Sign: The road long its repair far XI, I will go up and down and quest.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Some tips for using "Jade" jade