/page/faq
routers/page/index.js
router.all("page/faq$", function(req, res){
handler.renderHbs(req, res, "pages/page/faq", {
//default layout인 common.handlerbar 위에 해당 route에 있는 파일에 뒤 {} option들을 지역변수로 넣어서 render
commonPartials:true,
title:"문의하기" //metainfo로 넘어가는 : title 또는 헤더 title
stylesheets:[],
scripts:[]
})
})
pages/page/faq.handlebar
//category가 없으면 faq폴더의 index.handlebar
//page.faq.js : click 시 class:active 추가
//>뒤에 경로를 partials에 대한 경로로 추가해주는 곳?
//is(server.ts에서 handlerbar 인스턴스 생성 시 정의한 helper : 첫 인자와 두번째 인자가 같으면 {{}} 안 경로의 파일로 이동하라는 뜻인 듯)
{{#unless params.category}}{{> faq/index}}{{/unless}}
{{#is params.category "account"}}{{> faq/account}}{{/is}}
{{#is params.category "auth"}}{{> faq/auth}}{{/is}}
{{#is params.category "timetable"}}{{> faq/timetable}}{{/is}}
{{#is params.category "community"}}{{> faq/community}}{{/is}}
{{#is params.category "privacy"}}{{> faq/privacy}}{{/is}}
{{#is params.category "abuse"}}{{> faq/abuse}}{{/is}}
{{#is params.category "etc"}}{{> faq/etc}}{{/is}}
pages/partial/index.handlebar
params.category로 넣는 값 : a 태그로 href에 query로 값 넘겨줌
ex. /page/faq?category=auth
<a href="/page/faq?category=auth">
<li>
<h4>학교 인증</h4>
<p>합격자 인증, 재학생 인증, 졸업생 인증 등</p>
</li>
</a>
res.render(view [, locals][, callback])
Renders a view and sends the rendered HTML string to the client. Optional parameters:
locals: an object whose properties define local variables for the view.
callback: a callback function. If provided, the method returns both the possible error and rendered string, but does not perform an automated response. When an error occurs, the method invokes next(err) internally.
The view argument : a string that is the file path of the view file to render.
- This can be an absolute path, or a path relative to the views setting.
For more information, see Using template engines with Express.
cf. NOTE: The view argument performs file system operations like reading a file from disk and evaluating Node.js modules, and as so for security reasons should not contain input from the end-user.
cf. The local variable cache enables view caching. Set it to true, to cache the view during development; view caching is enabled in production by default.
// send the rendered view to the client
res.render('index')
// if a callback is specified, the rendered HTML string has to be sent explicitly
res.render('index', (err, html) => {
res.send(html)
})
// pass a local variable to the view
res.render('user', { name: 'Tobi' }, (err, html) => {
// ...
})