2017-08-12 22 views
1

我在我的_data文件夹中有一个YAML文件,其中包含我在主导航栏中的链接列表。液体:动态地隐藏占位符链接

_data/nav.yml

main: 

    - title: Link A 
    - url: "/path/to/linkA" 

    - title: Link B 
    - url: "/path/to/linkB" 

    - title: Link C 
    - url: "#" 

然后我用液体动态生成的链接。这是我的头文件的相关部分。

_includes/header.html

<nav class="quick-links"> 
    {% for item in site.data.nav.main %} 
    <a href="{{ item.url }}">{{ item.title }}</a> 
    {% if forloop.last == false %} :: {% endif %} 
    {% endfor %} 
</nav> 

将NAV输出为:

Link A :: Link B :: Link C 

想我的输出如下所示

Link A :: Link B 

因为​​是一个占位符。

我该如何动态地隐藏占位符链接,即链接为“#”作为href?

回答

1

首先,你需要正确组导航项YAML文件:

<nav class="quick-links"> 
    {% for item in site.data.nav.main %} 
    {% unless item.url contains "#" %} 
    <a href="{{ item.url }}"> 
    {{ item.title }} 
    </a> 
    {% if forloop.last == false %} :: {% endif %} 
    {% endunless%} 
    {% endfor %} 
</nav> 

main: 
    - 
    title: Link A 
    url: "/path/to/linkA" 
    - 
    title: Link B 
    url: "/path/to/linkB" 
    - 
    title: Link C 
    url: "#" 

然后你可以使用unless标签避免link c