This forum has moved, please join us on github discussions. We will keep these old posts available for reference. Thank you!

Can't get the apostrophe utility isEmpty to work

Im using code like this:

                {% if apos.utils.isEmpty(apos.areas.richText(data.page.heroHeadingMobile, { delimiter: ',' })) %}
                    test content {{ apos.areas.richText(data.page.heroHeading, { delimiter: ',' }) }}
                {% else %}
                    {{ apos.areas.richText(data.page.heroHeadingMobile, { delimiter: ',' }) }}
                {% endif %}

But I have also tried like this:

                {% if apos.utils.isEmpty(apos.areas.richText(data.page.heroHeadingMobile, { delimiter: ',' })) %}
                    test content {{ apos.areas.richText(data.page.heroHeading, { delimiter: ',' }) }}
                {% else %}
                    {{ apos.areas.richText(data.page.heroHeadingMobile, { delimiter: ',' }) }}
                {% endif %}

But I never seem to be able to get the else condition to fire:

I am using this inside another condition, not sure if that ok, here is an example of my complete code:

            <h1 class="hidden-sm hidden-md hidden-lg">
                {% if data.page._edit %}
                {{ apos.singleton(data.page, 'heroHeadingMobile', 'apostrophe-rich-text', {
                toolbar: ['Styles','Bold', 'Italic', 'Subscript', 'Superscript', 'Link', 'Unlink'],
                styles: [
                { name: 'Strong Font', element: 'span', attributes: { 'class': 'headline2'} }
                ]
                }) }}
                {% else %}

                {% if apos.utils.isEmpty(apos.areas.richText(data.page.heroHeadingMobile, { delimiter: ',' })) %}
                    test content {{ apos.areas.richText(data.page.heroHeading, { delimiter: ',' }) }}
                {% else %}
                    {{ apos.areas.richText(data.page.heroHeadingMobile, { delimiter: ',' }) }}
                {% endif %}

                {% endif %}
            </h1>

Ok i figured it out.

I need to check the items property.

data.page.heroHeadingMobile.items

instead of:

data.page.heroHeadingMobile

Like this:

                {% if apos.utils.isEmpty(data.page.heroHeadingMobile.items ) %}
                    {{ apos.areas.richText(data.page.heroHeading, { delimiter: ',' }) }}
                {% else %}
                    {{ apos.areas.richText(data.page.heroHeadingMobile, { delimiter: ',' }) }}
                {% endif %}

Seems like nested conditional statements are fine in Nunjucks templates to.