How do I set a class if entry is a child of a particular parent? I have a structure section which is three levels deep and I want to add a class when the entry has a parent id of X. I am trying something like:

{% for entry in craft.entries.section('brand').descendantOf(entry.id).level(3) %}
&lt;li class="nav--brand__item{% if entry.isAncestorOf(13) %} cs-g{% endif %}"&gt;
  ...
&lt;/li&gt;
{% endfor %}


This gives me a "Recoverable error":


  Argument 1 passed to Craft\BaseElementModel::isAncestorOf() must be an
  instance of Craft\BaseElementModel, string given


What am I doing wrong?

Updated code:

{% for entry in craft.entries.section('brand').descendantOf(entry.id).level(3) %}
{% set entryWithId13 = craft.entries.id(13).first() %}
{% set entryWithId23 = craft.entries.id(23).first() %}
{% set entryWithId23 = craft.entries.id(29).first() %}
&lt;li class="nav--brand__item{% if entryWithId13.isAncestorOf(entry) %} cs-h{% endif %}{% if entryWithId23.isAncestorOf(entry) %} cs-k{% endif %}{% if entryWithId29.isAncestorOf(entry) %} cs-h{% endif %}"&gt;
...
&lt;/li&gt;
{% endfor %}
If you want to test whether entry-with-id-X is an ancestor of entry, do this (assuming x = 13):

{% set entryWithIdX = craft.entries.id(13).first() %}
...
{% if entryWithIdX.isAncestorOf(entry) %} ... {% endif %}
{# or #}
{% if entry.isDescendantOf(entryWithIdX) %} ... {% endif %}


isAncestorOf and isDescendantOf take an entry as parameter, not an entryId.

It would be a good idea to test to see whether craft.entries.id(13) returns anything before calling first() on it, but that's a separate issue.