2014-12-29 4 views
1

지금은 nodejs를 배우고 있고 .ejs 템플릿 파일은 거의 표준 (헤더, 꼬리말, js-defaults 등)이며 변경 사항은 HTML div의 내용경로를 통한 동적 설정보기

내 경로에서 변수를 설정하고 뷰 (제목 또는 다른 변수처럼)에 전달한 다음 포함시킬 수 있다고 생각했지만 작동하지 않습니다 (아래 예 참조).

루비에서는 이것을 "yield"로 할 수 있으며 EJS에서도 동일한 작업을 수행하려고합니다.

시간을내어 읽어 주셔서 감사 드리며 (이 문제에 대한 내 무지를 용납 해주십시오.)

예 루트

app.get('/fish', function(req, res) { 

res.render('fish' { 
    title:"Fish", 
    template:"view/partials/content/fish.ejs" 
}); 

});

예 EJS는

<!DOCTYPE html> 
<html> 
<head> 
    <title><%= title %></title> 
</head> 
<% include views/partials/template/header.ejs %> 
<body> 
    <div class="container"> 
     <!-- Dynamic content here --> 
     <% include template %> <!-- tries to load template.ejs %> 
    </div> 
</body> 
<% include views/partials/template/footer.ejs %> 
<% include views/partials/template/js-defaults.ejs %> 
</html> 
+0

사용을'<%= title %>'대신'<% title %>'출력으로는, HTML로 레일 (.erb)에서와 같이. – Ravi

+0

감사합니다. @Ravi - 내 예를 들어 보겠습니다. 그것은 내가 붙어있는 역동적 인 내용입니다 - 그것이 작동하도록하는 방법을 모릅니다. – doublesidedstickytape

+1

글쎄, 이건 아직 지원 여부는 모르겠지만, 이것 좀 봐, https://github.com/tj/ejs/issues/93. – Ravi

답변

1

Looks like this is now supported in EJ는 S.는 그것은 v2.0.1: 2015-01-02에 도입 하였다. 새로운 구문이 내가 설정하여 Express에서 캐싱을 사용하지 않도록했다 작동하도록하기 위해이

<!-- Dynamic content here --> 
     <%- include(template) %> 

다음과 같습니다

app.set('view cache', false);