꼬물꼬물 개발자
뷰 구현 - EJS 주요 문법 본문
데이터 출력
- 라우팅 메서드에서 뷰에 전달된 데이터 출력
<%=데이터속성명%>
<%=title%>
if 가정문
<% if(userName == "한고운"){%>
<h3> 안녕하세요. </h3>
<%}else{%>
<h3> 안녕히가세요. </h3>
<%}%>
for 반복문
<% for(var i = 0; i < children.length;i++){%>
<%=i+1%>번째 이름은 <%=children[i].childName%> 나이는 <%=children[i].age%> 입니다.<br/>
<%}%>
입력 요소
<input type="text" id="userName" name="userName" value="<%=userName%>" />
데이터 전달
router.get('list',async(req,res,next) =>{
const channels = [
{
channel_id:1,
channel_name:"채널1"
},
{
channel_id:1,
channel_name:"채널1"
}
];
res.render('chnnel/list.ejs',{channels:channels});
});