Jade templating, variable scope in includes

前端 未结 1 1175
小鲜肉
小鲜肉 2021-01-11 23:09

I am using Jade (without Express, just for static HTML templating) - which I understood as able to create partials, meaning scope is not an issue, but this doesn\'t seem to

相关标签:
1条回答
  • 2021-01-12 00:03

    You could accomplish this with a mixin like so:

    master.jade

    include includes/header
    
    !!!
    html
      block vars
      - var slug= 'home'
      head
        block pagetitle
          title Static HTML
        link(rel='stylesheet', href='css/styles.css')
      body(class= slug)
        .wrapper
          mixin header(slug)
    

    includes/header.jade

    mixin header(klass)
      .header
        ul
          li(class= klass)
    

    When compiled:

    <!DOCTYPE html>
    <html>
      <head>
        <title>Static HTML</title>
        <link rel="stylesheet" href="css/styles.css">
      </head>
      <body class="home">
        <div class="wrapper">
          <div class="header">
            <ul>
              <li class="home"></li>
            </ul>
          </div>
        </div>
      </body>
    </html>
    
    0 讨论(0)
提交回复
热议问题