Skip to main content

Liquid error: undefined method `gsub' for nil:NilClass

Here's my code in _nav.html.  I'm trying to make certain menu items list all posts tagged with that menu item slug.  It works for the first child2 forloop, but then displays the error afterwards

{% for child2 in child.nav_children %}
{% if child2.nav_children.size > 0 or child2.parent.slug == 'topics' and child2.slug != 'hot_topics' and child2.slug != 'customized_conversations' %}
<li class="drop">
<a href="{{ child2.url }}">{{ child2.name }}<i class="icon-right-open"></i></a>
<ul class="subsub">

{% if child2.parent.slug == 'topics' and child2.slug != 'hot_topics' and child2.slug != 'customized_conversations' %} <!-- Making categories list topics instead of subpages/posts -->



{% tag child2.slug with "nav_category_topic_list" %} <!-- Get all posts with tag name -->

{% else %}

{% for child2child in child2.nav_children %}
<li>
<a href="{{ child2child.url }}">{{ child2child.name }}</a>
</li>
{% endfor %}

{% endif %}


</ul>
</li>
{% else %}
<li>
<a href="{{ child2.url }}">{{ child2.name }}</a>
</li>
{% endif %}
{% endfor %}

Official response from

Hey Peter, this unfortunately won’t work due to the use of a variable (child2.slug) as the target for the {% tag %} tag; you’ll need to hardcode the tag in question rather than pulling it dynamically.

Share this post

Showing 3 reactions

How would you tag this suggestion?
Please check your e-mail for a link to activate your account.