Getting Started With EJS
npm init -y
npm i express
body-parser
cors
ejs
- set up path/built in core module for node
- Set up express, body parser, cors
- set up instance of express
- Set up app.use for bodyParser and cors
- Path doesn’t need to be installed.
- Line 11 @ 3:29 takes two paths and joins them
Evaluate and Injected Variable
How to inject a value into EJS view and how to evaluate the variable.
using if/else in ejs
- also need ejs tag!!
- use this to determine what value will be evaluated and show on page.
Layouts
- not native to ejs
- useful to wrap information in file as you switch views between URLs
- add them by
npm i --save express ejs-layouts
- add in js example @1:50
- make sure there is an
app.use
for expresslayouts
- Use this to wrap content in a way which designate what will show on each webpage.
Partials
- are native to ejs
- useful for:
- nav bar
- footer
- reusable/static piece of text
- Example * 50sec
Helpful Resources