代码之家  ›  专栏  ›  技术社区  ›  tosi

布局定制与使用两种布局-expressjs

  •  1
  • tosi  · 技术社区  · 9 年前

    假设我有一个主要的 layout.handlebars 如果我定制,性能会有什么不同吗 这样地:

    <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>
    

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

    而不是为网站的两个部分分别使用两种不同的布局?

    1 回复  |  直到 9 年前
        1
  •  1
  •   Alex    9 年前

    性能没有受到影响,但最终会得到混乱的代码。
    如果出现“第3节”怎么办?另一个如果?

    那么...怎么样

    <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>
    

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

    或

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