質問

This is the code for my header menu:

<ul>
  {% for link in linklists.main-menu.links %}
  <li class="{% if forloop.first %}first{% elsif forloop.last %}last{%endif%}">
    {% assign child_list_handle = link.title | handleize %}
    {% if linklists[child_list_handle].links != blank %}
    <div class="has-dropdown">
      <a href="{{ link.url }}" class="clearfix">
        <span class="nav-label">{{ link.title | escape }}</span>
        <span class="nav-arrow"></span>
      </a>
      <ul>
        {% for childlink in linklists[child_list_handle].links %}
        <li><a href="{{ childlink.url }}">{{ childlink.title | escape }}</a></li>
        {% endfor %}
      </ul>
    </div>
    {% else %}
      <a href="{{ link.url }}">{{ link.title | escape }}</a>
    {% endif %}
  </li>
  {% endfor %}
</ul>

I am not sure what lanugage this is written in but I want to change it so that any item named "featrued" is not shown in the menu. The sudo code would be something like this:

if name!="featured" then {  ...    }...

This is what I tried:

{% if link.title != featured %}
...
{% endif %}

Could anyone please help me understand what adjustment would need to be made?

役に立ちましたか?

解決

You're close! You just need to enclose the link's title in quotation marks.

Try this:

<ul>
  {% for link in linklists.main-menu.links %}
    {% if link.title != 'featured' %}
      <li class="{% if forloop.first %}first{% elsif forloop.last %}last{%endif%}">
        ...
      </li>
    {% endif %}
  {% endfor %}
</ul>
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top