We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Nested Relationship Code

Developer Preview

Boyink!'s avatar
Boyink!
5,011 posts
11 years ago
Boyink!'s avatar Boyink!

Hey folks - I’m testing this code that I’ve had in the book for demonstrating nesting advanced relationships - and it’s not working in 2.9:

<h2>The Family Tree from the Top Down </h2>
    {exp:channel:entries channel="people" disable="member_data|pagination|categories"}
      
      {if count==1} {!-- start the top-level unordered list --}
        <ul>
      {/if}

        {parents field="offspring"}
            {if parents:no_results} {!-- entries with no parents are top-level --}
                <li>
                  {title}
                  {offspring} {!-- second level entries --}
                   
                    {if offspring:count == 1}<ul>{/if} {!-- open the second-level unordered list --}
                    
                        <li>
                          {offspring:title}
                          {offspring:offspring} {!-- third level entries --}
                            
                            {if offspring:offspring:count == 1}
                              <ul> {!-- open 3rd level list --}
                            {/if}

                            <li>{offspring:offspring:title}</li>
                            
                            {if offspring:offspring:count==offspring:offspring:total_results}
                              </ul> {!-- close third-level list --}
                            {/if}

                          {/offspring:offspring}
                        </li>

                    {if offspring:count==offspring:total_results}
                      </ul> {!-- close second-level list --}
                    {/if}
                   
                  {/offspring}
                </li>
            {/if}
        {/parents}

        {if count==total_results}
          </ul> {!-- close top-level list --}
        {/if}
    {/exp:channel:entries}

I get

Error You have an invalid conditional in your template. Please review your conditionals for an unclosed string, invalid operators, a missing }, or a missing {/if}. Parser State: Unexpected end of Template “tree/recursive” on line 56; expected ENDIF tag for opening on line 25.

Line 25 in the template editor is:

{if offspring:count == 1}<ul>{/if} {!-- open the second-level unordered list --}
       
Boyink!'s avatar
Boyink!
5,011 posts
11 years ago
Boyink!'s avatar Boyink!

Any thoughts here guys?

I hate to nag but this is the final issue remaining in an update of my book.

       
Seth Barber's avatar
Seth Barber
172 posts
11 years ago
Seth Barber's avatar Seth Barber

Hi Boyink!

I’m digging into this and will let you know when I have something solid.

       
Seth Barber's avatar
Seth Barber
172 posts
11 years ago
Seth Barber's avatar Seth Barber

We found the problem: it is in the {if parents:no_results} statement which wasn’t accounting for nested conditionals. The following patch should fix it.

In system/expressionengine/libraries/relationship_parser/Parser.php on line 278 replace:

return ($whole_tag ? $match[0] : $match[1]);

with

if (stristr($match[1], LD.'if'))
{
 $match[0] = ee()->functions->full_tag($match[0], $node_tagdata, LD.'if', LD.'\/'."if".RD);
}

if ($whole_tag)
{
 return $match[0];
}

return substr($match[0], strlen(LD."if {$tag}:no_results".RD), -strlen(LD.'/'."if".RD));

Let me know if that works on your end.

       
Boyink!'s avatar
Boyink!
5,011 posts
11 years ago
Boyink!'s avatar Boyink!

Yep - looks good in my test install

Thanks!

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.