<p>The containment operator in does have problems working with whole element models. I'd try and modify your conditional to compare entry IDs instead:</p>

<pre><code>{% if entry.id in craft.entries.section('general').descendantOf(42).ids() %}
    ...
{% endif %}
</code></pre>

<p>To include that parent page ID to that array you would do that with the merge filter:</p>

<pre><code>{% set aboutPagesIds = craft.entries.section('general').descendantOf(42).ids() %}
{% set aboutPagesIds = aboutPagesIds|merge([42]) %}
</code></pre>

CC BY-SA 3.0
2015-05-11T11:06:33.493Z
Thank you, this worked, but is there a way to check for the parent as well as the descendant in the same if statement? It would include `{% if entry.id == 174 %}` and `{% if entry.id in craft.entries.section('general').descendantOf(42).ids() %}` together?
jsilton
CC BY-SA 3.0
2015-05-11T11:16:00.807Z
@jsilton I updated my answer. You could also combine the conditionals with `or`, but I like the above method better.
carlcs
CC BY-SA 3.0
2015-05-11T05:58:57.560Z
2015-05-11T11:10:43.250Z
2015-05-11T11:10:43.250Z
carlcs
<p>I was able to make some progress here. Below is the proper navigation aligned for the parent entries, but not the children.</p>

<pre><code>{% if entry.id == 174 %}
 {% nav node in craft.menus.getNodes('ticketsSubnav') %}
 &lt;li&gt;&lt;a href="{{node.link}}"&gt;{{ node.title }}&lt;/a&gt;&lt;/li&gt;
 {% endnav %}
{% endif %}

{% if entry.id == 53 %}
 {% nav node in craft.menus.getNodes('visitSubnav') %}
 &lt;li&gt;&lt;a href="{{node.link}}"&gt;{{ node.title }}&lt;/a&gt;&lt;/li&gt;
 {% endnav %}
{% endif %}

{% if entry.id == 42 %}
 {% nav node in craft.menus.getNodes('aboutSubnav') %}
 &lt;li&gt;&lt;a href="{{node.link}}"&gt;{{ node.title }}&lt;/a&gt;&lt;/li&gt;
 {% endnav %}
{% endif %}

{% if entry.id == 57 %}
 {% nav node in craft.menus.getNodes('supportSubnav') %}
 &lt;li&gt;&lt;a href="{{node.link}}"&gt;{{ node.title }}&lt;/a&gt;&lt;/li&gt;
 {% endnav %}
{% endif %}
</code></pre>

<p>It's still not the answer yet, but closer.</p>

CC BY-SA 3.0
2015-05-11T00:20:22.497Z
2015-05-11T00:20:22.497Z
jsilton
<p>I have setup a few different navigation lists through the Menus 0.9 plugin by Familiar. Within my website, I have setup several different site sections all through the same structure called, "General". They all share the same page template.</p>

<p>I would like to run a check to see if the page is "About" or is a child of "About" (all within the "General Structure"). If it is "About" or a child of "About", I would like to server it a specific sub-nav.</p>

<p>Here's the code to run that subnav:</p>

<pre><code>{% nav node in craft.menus.getNodes('aboutSubnav') %}
&lt;li&gt;&lt;a href="{{node.link}}"&gt;{{ node.title }}&lt;/a&gt;&lt;/li&gt;
{% endnav %}
</code></pre>

<p>How do I do the lookup to see what page it is? I tried the following code, but it did not work:</p>

<pre><code>{% if entry in craft.entries.section('general').descendantOf(42) %}
 {% nav node in craft.menus.getNodes('aboutSubnav') %}
 &lt;li&gt;&lt;a href="{{node.link}}"&gt;{{ node.title }}&lt;/a&gt;&lt;/li&gt;
 {% endnav %}
{% endif %}
</code></pre>

<entries><structure><navigation>
Check Structure for Entry or Child of Entry
# Check Structure for Entry or Child of Entry

(Asked by: username_0 on 2015-05-11)

I have setup a few different navigation lists through the Menus 0.9 plugin by Familiar. Within my website, I have setup several different site sections all through the same structure called, "General". They all share the same page template.
I would like to run a check to see if the page is "About" or is a child of "About" (all within the "General Structure"). If it is "About" or a child of "About", I would like to server it a specific sub-nav.
Here's the code to run that subnav:
{% nav node in craft.menus.getNodes('aboutSubnav') %}
{{ node.title }}
{% endnav %}

How do I do the lookup to see what page it is? I tried the following code, but it did not work:
{% if entry in craft.entries.section('general').descendantOf(42) %}
 {% nav node in craft.menus.getNodes('aboutSubnav') %}
 {{ node.title }}
 {% endnav %}
{% endif %}

**Tags:** entries, structure, navigation

---

## 2 answers

### Answer by username_1 on 2015-05-11. Score: 2 | Accepted answer

The containment operator in does have problems working with whole element models. I'd try and modify your conditional to compare entry IDs instead:
{% if entry.id in craft.entries.section('general').descendantOf(42).ids() %}
    ...
{% endif %}

To include that parent page ID to that array you would do that with the merge filter:
{% set aboutPagesIds = craft.entries.section('general').descendantOf(42).ids() %}
{% set aboutPagesIds = aboutPagesIds|merge([42]) %}

> **Comments:**
> **username_0**: Thank you, this worked, but is there a way to check for the parent as well as the descendant in the same if statement? It would include `{% if entry.id == 174 %}` and `{% if entry.id in craft.entries.section('general').descendantOf(42).ids() %}` together?  
> **username_1**: @jsilton I updated my answer. You could also combine the conditionals with `or`, but I like the above method better.  

---

### Answer by username_0 on 2015-05-11. Score: 1

I was able to make some progress here. Below is the proper navigation aligned for the parent entries, but not the children.
{% if entry.id == 174 %}
 {% nav node in craft.menus.getNodes('ticketsSubnav') %}
 {{ node.title }}
 {% endnav %}
{% endif %}

{% if entry.id == 53 %}
 {% nav node in craft.menus.getNodes('visitSubnav') %}
 {{ node.title }}
 {% endnav %}
{% endif %}

{% if entry.id == 42 %}
 {% nav node in craft.menus.getNodes('aboutSubnav') %}
 {{ node.title }}
 {% endnav %}
{% endif %}

{% if entry.id == 57 %}
 {% nav node in craft.menus.getNodes('supportSubnav') %}
 {{ node.title }}
 {% endnav %}
{% endif %}

It's still not the answer yet, but closer.


---

