2

I have a list of related entries on a single entry page. I only want to show surrounding code if there are related entries. I know related entries has been changed recently so I'm stuck.

I would expect the following conditional to work but it doesn't.

{if cf_article_related}
    <aside>
      <h2>Further Reading</h2>
      <ul>
        {cf_article_related}<li><a href="{cf_article_related:url_title}"> {cf_article_related:title}</a></li>
{/cf_article_related}
      </ul>
    </aside>
{/if}

I'm sure it'll be something obvious but I would love to know how to do this!

Cheers, Mike

5

The documentation is confusing on the EL site. If you prefix the single tags variables count & total_results with the custom field name, you will have access to control your markup with conditionals. This should work:

{cf_article_related}
    {if cf_article_related:count == 1}
        <aside>
        <h2>Further Reading</h2>
        <ul>
    {/if}

    <li><a href="{cf_article_related:url_title}"> {cf_article_related:title}</a></li>

    {if cf_article_related:count == cf_article_related:total_results}
        </ul>
        </aside>
    {/if}

    {if cf_article_related:no_results}NOTHING FOUND{/if}
{/cf_article_related}
0

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.