Templating Engines: Pug/Jade Flashcards
Adding attributes and button name to a button tag inside a form
form button(type='submit') Button Name
creating a button with the class ‘btn, btn-danger’
button.btn.btn-danger
installing pug on the server side
npm/yarn install/add pug –save
pug has build-in integration with express.
using a dynamic variable
{var} or () inside tag attributes
note: javascript string interpolation uses ${}, while pug uses #{}
built-in method to iterate through a dynamic var
each val in obj
built in method to check for a condition
if condition //do something
What is the fundamental tag to create a template .pug file?
block (name)
How to import a file and write over its template?
extends (file path)
block (name)
// code
creating a switch case with a built-in pug expression
case expression when val // do stuff when val2 // do stuff when val3 when val4 //fall through also works default // something
writing an inline for loop that returns a list of items with the inline javascript capabilities pug offers
- for (var i = 0; i < 9; i++) li loop number ${i}
writting block unbuffered code
- var obj = {var1: 1, var2: 2, var3: 3} each val in obj li #{val}
note: javascript string interpolation uses ${}, while pug uses #{}
writting inline buffered code
h2= ‘buffered supports all’ + ‘javascript expressions’ + var;
writting buffered unscaped(unsafe) code
li!= “dangerous code! <this>"</this>
why is unscaped code unsafe?
because it allows for XSS (cross-site-scripting) in which user can insert client-side javascript code into your site.
writing a p tag with a text block
p.
text
text
text