ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Need Help Understanding Related Entries Syntax

August 25, 2012 10:50am

Subscribe [3]
  • #1 / Aug 25, 2012 10:50am

    Ed Hebert

    49 posts

    Hi-

    I don’t often use related_entries functionality, but I need it now. I’ve read all the EE documentation, but I’m not getting the expected results from my templates. I’m banging my head against a wall trying to understand the logic / syntax.

    In short, I have a “products” channel with a relationship field from the same channel. This relationship allows a subproduct to be connected to a main product when appropriate. For example, “Louvered Interior Shutters” as a subproduct entry of the “Interior Shutters” entry (both of which are in the “Shutters” Channel.

    I want my template to test whether the current entry is a “parent” page. If so, show some of its relevant “parent page” fields, and then list links to the subordinate pages. If it’s not a parent page, then go ahead and show a different set of details of the page. I’m using the same template for both conditions.

    In the code I’ve created, nothing in the “if no_reverse_related_entries” conditional is being parsed. No custom fields, and not even fields like {title}. Those fields get sent as plain text, and render as “{title}” right on the page.

    Aside from the specific issues with the reverse_related_entries conditional, am I even approaching this the right way logically, or is there a cleaner, more intuitive solution?

    Thanks for your help.

    My products/index.html template looks like this:

    {exp:channel:entries channel="products"}
    {reverse_related_entries}
    
    <a href="http://{url_title_path=products}">{url_title}</a>  {!-- build some links to the subproduct pages if appropriate --} 
    
    {if no_reverse_related_entries} {!-- its an end level page, so show a bunch of details --}
        <div class="span5">
            <h2 class="underline">{title}</h2>
            {page}
            {edit_this}
        </div>
        <div class="span6 offset1">
            <ul class="thumbnails">
                {exp:channel_images:images entry_id="{entry_id}"}
                    <li class="span2"><a href="http://{image:url:medium}" rel="group" title="{image:description}" class="thumbnail fancybox">{image:url:small}</a></li>
                {/exp:channel_images:images}
            </ul>
        </div>
    {/if}  {!-- no_reverse_related_entries --}     
    {/reverse_related_entries}                    
    {/exp:channel:entries}
  • #2 / Aug 26, 2012 8:26am

    Ed Hebert

    49 posts

    Specifically, it seems that nothing inside the {if no_reverse_related_entries} conditional gets parsed. Am I not allowed to use any EE variables or custom fields inside that conditional?

  • #3 / Aug 27, 2012 11:12am

    Rob Allen

    3114 posts

    At a guess it may be related to parse order?

    Have you tried conditionals here?

    {exp:channel:entries channel="products"}
    {reverse_related_entries}
    
    {if count >= 1}
    <a href="http://{url_title_path=products}">{url_title}</a>
    {/if}
    
    {if count == 0}
    No reverse related entries code
    {/if}
    
    {/reverse_related_entries}                    
    {/exp:channel:entries}
  • #4 / Aug 27, 2012 11:25am

    Ed Hebert

    49 posts

    Thanks, bluedreamer. I hadn’t tried that. I actually just used PHP to solve the problem, but next time I’ll try using a conditional with count.

  • #5 / Aug 27, 2012 11:55am

    Shane Eckert

    7174 posts

    Hey guys,

    Nice work here. You guys are a great example of why the community here is so awesome.

    If you need anything else, please just let me know by opening a new thread.

    Cheers,

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases