2

If there are review entries related to the current entry then I would like to display it as follows:

<aside id="reviews">
    <h3>Reviews</h3>
{reverse_related_entries channel="review"}
    <article>
        <h4>{title}</h4>
        {review_body}
    </article>
{/reverse_related_entries}
</aside>

If there are no reviews then I do not want to display anything.

I could just add a JavaScript which removes the empty "Reviews" section, but I would rather it wasn't outputted if possible.

6

Wouldn't this work?

{reverse_related_entries channel="review"}
{if count == "1"}
<aside id="reviews">
<h3>Reviews</h3>
{/if}
<article>
    <h4>{title}</h4>
    {review_body}
</article>
{if count == total_results}</aside>{/if}
{/reverse_related_entries}
| improve this answer | |
  • Interesting thanks! Do you know off the top of your head if {if count % 4 == 0} works? – Lea Hayes Dec 14 '12 at 12:01
  • Pretty sure it doesn't - but you could always enable php in your template and do it that way. – erwinheiser Dec 14 '12 at 12:57
  • 1
    Yeah, not without PHP in the template or a Plugin. If you don't want to use PHP in your template then Modulo Operator or SugarEE will enable you to use modulo in your templates. There is also the native switch variable which is handy but can get messy depending on what you need to do. – Alex Kendrick Dec 14 '12 at 16:02
  • More on the topic of modulo and {switch} can be found in the answers to this question. – Alex Kendrick Dec 14 '12 at 18:11
0

Do you know off the top of your head if {if count % 4 == 0} works

I'd never considered the EE could use modulus. I haven't tested but a quick look at the docs and it isn't listed: http://ellislab.com/expressionengine/user-guide/templates/globals/conditionals.html#comparison-operators

I've done this many time by just enabling PHP for the template.

*NB Not sure how can you to reply to a thread of someone else's answer.

| improve this answer | |

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.