Jade: Change active menu item in parent template

后端 未结 4 839
孤街浪徒
孤街浪徒 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:25

    Here's a simpler way:

    Use this in your layout.jade (where nav is the name of the page that's active. nav = 'about' for example)

    ul(class="#{nav}")
      li.home Home
      li.blog Blog
      li.contact Contact Us
      li.about About
    

    Then put this is your CSS:

    ul.home li.home,
    ul.blog li.blog,
    ul.contact li.contact,
    ul.about li.about {
        color: red;
    }
    

    The only css rule that will apply is the one whose ul class exists. You'll need to pass in a variable nav that equals 'about', 'home', 'contact', or 'blog' depending on what page you're on.

提交回复
热议问题