tosi
tosi

Reputation: 621

layout customisation vs using two layouts - expressjs

Let's say I have one main layout.handlebars and a website with two main sections. Would there be any performance difference if I customized layout.handlebars like this:

<head>
 <title>{{title}}</title>

 <link href="css/bootstrap.css" rel="stylesheet">
 {{#if section1}}
 <link href="css/section1.css" rel="stylesheet">
 {{else}}
 <link href="css/section2.css" rel="stylesheet">
 {{/if}}

</head>

And rendered like this:

router.get('/section1', function(req, res){
    res.render('section1',{title: 'Section 1', section1: true});
});

Instead of using two different layouts each for both sections of the website?

Upvotes: 1

Views: 21

Answers (1)

Alex
Alex

Reputation: 38529

No performance hit, but you'll end up with messy code.
What if 'section 3' comes along? Another if?

What about

<head>
 <title>{{title}}</title>

 <link href="css/bootstrap.css" rel="stylesheet">
 <link href="css/section1.css" rel="stylesheet">
 <link href="css/section{{section}}.css" rel="stylesheet">
</head>

Render it something like:

router.get('/section1', function(req, res){
    res.render('section1',{title: 'Section 1', section: "1"});
});

or

router.get('/section2', function(req, res){
    res.render('section2',{title: 'Section 2', section: "2"});
});

Upvotes: 1

Related Questions