node.js - Curious to Knowing The Best Way To Use Handlebars Partials Based On Express Render Variables -
so i'm wondering best way load handlebars partial in express when have render variable set.
app.get('/raves-reviews/corporate-clients', function (req, res) { res.render('raves-reviews.html', { //this of micro layout layout: 'main', //this main layout title: 'raves & reviews', corporate: true, //this part of idea 1 page: 'corporate-clients' //this part of idea 2 , 3 }); }); so when user goes mysite.com/raves-reviews/corporate-clients, handlebars first load main layout, have setup navigation show either home page slider, or raves-review slider if not home page.
then it'll load raves-reviews.html page, handlebars file i've renamed extension .html, micro template house 4 other pages.
what don't want have make 4 pages, same raves-reviews.html micro template , have include each of other pages partials. i'd rather make 1 page able handle every partial needs main layout every other page in website.
so idea 1, creating 4 {{ #if }} blocks in raves-reviews.html
{{#if page1}} {{> page1}} {{/if}} {{#if page2}} {{> page2}} {{/if}} {{#if page3}} {{> page3}} {{/if}} {{#if page4}} {{> page41}} {{/if}} so idea 2 use helper found here: logical operator in handlebars.js {{#if}} conditional create pages, did read there handlebars suppose free of logic. i'm not sure if method invoking logic templating system designed used without logic.
idea 3 see if there way use page variable in app.get create partial, i'm not 100% sure how pull off. original idea do:
{{> {{page}} }} if there other ways i'm totally open other ideas. everyone.
you should go option 1, because did it
Comments
Post a Comment