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>
사용을'<%= title %>'대신'<% title %>'출력으로는, HTML로 레일 (.erb)에서와 같이. – Ravi
감사합니다. @Ravi - 내 예를 들어 보겠습니다. 그것은 내가 붙어있는 역동적 인 내용입니다 - 그것이 작동하도록하는 방법을 모릅니다. – doublesidedstickytape
글쎄, 이건 아직 지원 여부는 모르겠지만, 이것 좀 봐, https://github.com/tj/ejs/issues/93. – Ravi