How to put some JavaScript in your JavaScript template: Jade

if we want to use any JavaScript at template compilation time—in other words, to write executable JavaScript code that manipulates the output of the Jade (i.e., HTML)—we can use the -, =, or != symbols. This might come in handy when we output HTML elements and inject JavaScript. Obviously, these types of things should be done carefully to avoid cross-site scripting (XSS) attacks. For example, if we want to define an array and output symbols, we can use !=.

When it comes to comments, we have a choice to output them or not. For the former, use JavaScript style //; for the latter, use //-.

Interestingly enough, in addition to the standard JavaScript code where the if statement can be used by prefixing it with -, we can use a minimalistic Jade alternative with no prefix and no parentheses

Iterations (each loops)Similar to conditions, iterators in Jade can be written simply with each

Source: To Engineers Who Tried to Use Jade Template Engine and Can’t Get Started

Leave a Reply

Your email address will not be published. Required fields are marked *