let ejs = require('ejs');
let people = ['geddy', 'neil', 'alex'];
let html = ejs.render('<%= people.join(", "); %>', {people: people});
//template string, data를 넘기면 HTML이 생긴다
template file, data file을 주고 output file을 정의한다
ejs ./template_file.ejs -f data_file.json -o ./output.html
let template = ejs.compile(str, options); /
template(data);
// => Rendered HTML string
data와 option을 함께
ejs.render(str, data, options);
// => Rendered HTML string
파일 렌더링하는 방법
ejs.renderFile(filename, data, options, function(err, str){
// str => Rendered HTML string
});
ex. "./views/users.ejs" , "./views/user/show.ejs"가 있으면
you would use <%- include('user/show'); %>.
You'll likely want to use the raw output tag (<%-) with your include to avoid double-escaping the HTML output.
- <% 'Scriptlet' tag : for control-flow, no output
- <%_ ‘Whitespace Slurping’ Scriptlet tag: strips all whitespace before it
- <%= : Outputs the value into the template (HTML escaped) : html에 변수를 넣는다
- <%- : Outputs the unescaped value into the template
- <%# : Comment tag, no execution, no output
- <%% : Outputs a literal '<%'
- %> : Plain ending tag
- -%> : Trim-mode ('newline slurp') tag, trims following newline
- _%> : ‘Whitespace Slurping’ ending tag, removes all whitespace after it