2015-10-20 95 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/ –

相关问题