Jade: Change active menu item in parent template

后端 未结 4 835
孤街浪徒
孤街浪徒 2020-12-13 02:56

I have a navigation bar in my parent jade template and I\'d like to highlight the item which is currently in view. So if I\'m on the blog page,

ul
  li Home         


        
4条回答
  •  鱼传尺愫
    2020-12-13 03:18

    parent.jade

    doctype 5
    
    html
      block link
        -var selected = 'home'; //default
    
      -var menu = { 'home': '/home', 'blog': '/blog', 'contact': '/contact' };
    
      body
        nav
          ul
            each val, key in menu
              li
                if selected === key
                  a.selected(href=val, title=key)= key
                else
                  a(href=val, title=key)= key
    

    child.jade

    extends parent
    
    block link
      -var selected = 'blog';
    

提交回复
热议问题