1

I have two equal variables comparing each other which give me false. One variable is set out of ancestor entry in structure and another one out of ancestor entry as well. Both variables are set a bit differently.

{% set parent = craft.entries.ancestorOf(entry).order('lft desc').first() %}

Following variable is set within table field

{% for row in entryId.table %}

    {% set id = row.entryId %}
    {% set rowParent = craft.entries.ancestorOf(id).order('lft desc').first() %}

    {% if rowParent == parent %}
        // Go
    {% endif %}

{% endfor %}

Both variables print the same text with case sensitive letters and spaces.

3

It seems like you're trying to compare two EntryModel objects. Could you just compare their ids?

{% if rowParent.id == parent.id %}
    // Go
{% endif %}

Also, try using Twig's dump() function to find out exactly what's in those variables/objects.

<pre>
    {{ dump(parent) }}
</pre>

I believe you'll have to have devMode enabled to use dump().

  • Yes, just after I've posted the question it hit me to compare it with ID variable as comparing strings didn't work. I still don't know why. Dumping EntryModels IDs gave me string length with an ID. It works now as expected. – Dominik Krulak Jan 12 '17 at 14:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.