2018-09-10 Section 24 Intermediate Express

Templates and EJS

#Rendering HTML and Templates 

1, Use res.render() to render Html (from an EJS file)


2,Explain what EJS is and why we use it 

embedded javascrpt, EJS是一个JavaScript模板库,用来从JSON数据中生成HTML字符串。

3,Pass variables to EJStemplates

app.js


2018-09-10 Section 24 Intermediate Express_第1张图片

love.ejs

#EJS control Flow

1, Show examples of control flow in EJS templates

<%=  %> equal sign will take the return value and stick it in HTML

<%  %> no equal will just run the code 

2,Write if statements in an EJS file


2018-09-10 Section 24 Intermediate Express_第2张图片

3Write loops in an EJS file


2018-09-10 Section 24 Intermediate Express_第3张图片

#Styles and partials 

1 show how to properly include public assets


2, properly configure our app to use EJS 


3 Use partials to dry up our code 

ejs file

2018-09-10 Section 24 Intermediate Express_第4张图片

header.ejs

2018-09-10 Section 24 Intermediate Express_第5张图片

footer.ejs


#post Requsts!!

1, write post routes, and test them with postman 


2018-09-10 Section 24 Intermediate Express_第6张图片

2,use a form to send a post request 


2018-09-10 Section 24 Intermediate Express_第7张图片

3 use body parser to get form data


2018-09-10 Section 24 Intermediate Express_第8张图片

你可能感兴趣的:(2018-09-10 Section 24 Intermediate Express)