Expression Engine导航和条件

时间:2013-08-13 21:54:36

标签: css navigation expressionengine conditional

提前感谢您对此问题的帮助。这是一个Expression Engine网站。我在导航,活动状态的简单条件方面遇到了麻烦。我在风格中放置了一个活跃的颜色状态;但是,“if语句”本身似乎存在问题,因为当我检查元素时,它们会在代码中呈现(导航是嵌入的)。

<nav class="group" role="navigation">
    <ul id="nav" class="group">
        <li class="first"><a {if segment_1 == ""} class="active" {/if}  href="{site_url}"><strong>Now</strong></a></li>
        <li><a {if segment_1 == "articles"} class="active" {/if} href="/articles/"><strong>articles</strong></a></li>
        <li><a {if segment_2 == "readings"} class="active" {/if} href="/book-readings/readings"><strong>books</strong></a></li>
        <li class="last"><a {if segment_2 == "readings"} class="active" {/if} href="/shelf/readings"><strong>shelf</strong></a></li>
    </ul>
</nav>

1 个答案:

答案 0 :(得分:0)

尝试:

<nav class="group" role="navigation">
    <ul id="nav" class="group">
        <li class="first"><a {if "{segment_1}" == ""} class="active" {/if}  href="{site_url}"><strong>Now</strong></a></li>
        <li><a {if "{segment_1}" == "articles"} class="active" {/if} href="/articles/"><strong>articles</strong></a></li>
        <li><a {if "{segment_2}" == "readings"} class="active" {/if} href="/book-readings/readings"><strong>books</strong></a></li>
        <li class="last"><a {if "{segment_2}" == "readings"} class="active" {/if} href="/shelf/readings"><strong>shelf</strong></a></li>
    </ul>
</nav>

要确认,请说明:

  

他们在代码中呈现

我假设你的意思是所有这些,因此建议将变量包装在引号和大括号中。但是你会遇到最后两个条件的问题,因为它们总是匹配在一起。如果这实际上是您的问题,那么解决方案是比较两个段:

        <li><a {if "{segment_1}" == "book-readings" && "{segment_2}" == "readings"} class="active" {/if} href="/book-readings/readings"><strong>books</strong></a></li>
        <li class="last"><a {if "{segment_1}" == "shelf" && "{segment_2}" == "readings"} class="active" {/if} href="/shelf/readings"><strong>shelf</strong></a></li>