본문 바로가기
Node.js/EJS (Embedded JavaScript Templating

To Do List 3] EJS 탬플릿으로 평일, 주말 글자색 다르게 하기 | EJS 태그

by CodeMia 2021. 10. 30.

주말인 경우 빨간 글씨로, 평일인 경우 하늘색

 

 

 

 

list.ejs

 

한 파일에 js, html 같이 있게 되었다. 

각 줄마다 ejs 태그를 씌여준다.

js는 <%  %>

html은 <%=  %>

 

결과 

 

 


 

 

ejs 태그 

https://ejs.co/

 

<% 'Scriptlet' tag, for control-flow, no output

 

control-flow: ELSE-IF, Switch, While statement,,

this allows you to render different HTML depending on what was the value of variable you got passed in to the template

 

scriptlet: 모든 종류의 자바스크립트를 쓸 수 있는 것이 아니어서 a full script tag가 아니다.

you have to add it around any part of your code that is not HTML 

각 라인 별로 각각 scriplet 태그를 씌여줘야한다. 

 

<%= Outputs the value into the template (HTML escaped)

<h1 style="color: red "> <%= kindOfDay %> list </h1>

<%=  %> 은 html 태그 h1 안에 들어있다 . 

 

 

 

 

 

댓글