2015-10-20 41 views
0

我正在使用節點排序來確定Jekyll中子文件夾中的頁面。此圖片顯示我的文件夾結構:在Jekyll中篩選子頁面並添加類

folder structure

所以我們可以說我有http://localhost/grain/ahvsuperb/頁面(如下圖所示爲index.html)。導航到此頁面將顯示添加到該鏈接的類on。這工作正常。

我遇到麻煩的時候是當我導航到一個頁面,如http://localhost/grain/ahvsuperb/features/。當我導航到該頁面時,indexfeatures已將on類添加到他們。任何有關如何過濾液體的見解?

<div class="content_nav"> 
    <ul class="content_nav"> 
    {% assign sorted_pages = site.pages | sort: 'weight' %} 
    {% for node in sorted_pages %} 
     {% if node.title != nil and node.url != '/' %} 
     {% capture nodediff %}{{ page.url | remove:node.url }}{% endcapture %} 
     <li><a {% if nodediff != page.url %}class="on" {% endif %}href="{{node.url}}">{{node.title}}</a></li> 
     {% endif %} 
    {% endfor %} 
    <li style="float:right"><a class="brochured" href="javascript:void(0);" rel="#brochuredl">Brochure</a></li> 
    <li style="float:right"><a class="quoted" href="#">Get a Quote</a></li> 
    </ul> 
</div> 

謝謝!

+0

無法重現。你有一些存儲庫可以顯示嗎? –

回答

0

您的{% capture nodediff %}{{ page.url | remove:node.url }}{% endcapture %}然後{% if nodediff != page.url %}未返回預期的頁面確定。

這將做的工作:

<div class="content-nav"> 
    <ul class="content-nav"> 
    {% assign sorted_pages = site.pages | sort: 'weight' %} 
    {% for node in sorted_pages %} 
     {% if node.title != nil and node.url != '/' %} 
     <li><a {% if node.url == page.url %}class="on" {% endif %}href="{{node.url}}">{{node.title}}</a></li> 
     {% endif %} 
    {% endfor %} 
    <li style="float:right"><a class="brochured" href="javascript:void(0);" rel="#brochuredl">Brochure</a></li> 
    <li style="float:right"><a class="quoted" href="#">Get a Quote</a></li> 
    </ul> 
</div> 
+0

釘釘了!謝謝大衛! – josiahwiebe

+0

所以我要重新打開這個...現在我繼續研究這個,我又添加了一個「部分」。我遇到的問題是所有頁面都顯示所有的子頁面,不管父母是什麼。你可以在這裏看到文件夾結構(https://www.dropbox.com/s/4txa9yufjpykhx7/Screenshot%202015-12-17%2012.23.06.png?dl=0)。如果您有任何見解,請告訴我。 – josiahwiebe

+0

你可以試試這個http://stackoverflow.com/a/33305868/1548376或http://thinkshout.com/blog/2014/12/creating-dynamic-menus-in-jekyll/ –

相關問題