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

Bug with multiple parents tags?

Development and Programming

eloyer17's avatar
eloyer17
8 posts
5 years ago
eloyer17's avatar eloyer17

Hi, I’m wondering if I’ve found a bug or am just misunderstanding how the {parents} tag is supposed to work. I’ve got a page with multiple {parents} tags with different offset and limit parameters, but only the first one seems to work correctly—the rest ignore their offset and limit parameters and only seem to show the second related parent item. Any suggestions? Thanks…

       
meatpaste's avatar
meatpaste
16 posts
5 years ago
meatpaste's avatar meatpaste

There is a known issue in 5.2.4 relating to relationships - https://github.com/ExpressionEngine/ExpressionEngine/issues/247, if this doesn’t sound like what you are experiencing it might help if you posted your EE version and some template code which demonstrates the problem.

       
eloyer17's avatar
eloyer17
8 posts
5 years ago
eloyer17's avatar eloyer17

I’m on version 5.2.3. I’ve got two channels, one called ‘project’ and one called ‘project_images’ which has a relationship field that links to the ‘project’ channel, and a field called ‘filename’ containing the path to an image describing the project. Each project has multiple images linked to it. Like so:

Project

  • [various fields]

Project Images

  • filename / Text
  • project / Relationship to Project

With the code below, the image in the second {parents} tag will always show the first related image, unless its order parameter is the same as in the first {parents} tag. So the example here will show image 2 (because its offset is set to 1) and then image 1 (even though its offset should make it show image 3). If I set the second offset to 1, the second image will correctly show image 2 (since its offset is the same as in the first {parents} tag).

Basically, it seems like the second {parents} tag can only show the first related item, or the item with the same offset as used in the first {parents} tag. Hope this is helpful.

{exp:channel:entries channel="project" limit="1"}
 {parents channel="project_images" orderby="url_title" sort="asc" offset="1" limit="1"}
  <img src="/images/site_images/{parents:filename}" />
 {/parents}        
 {parents channel="project_images" orderby="url_title" sort="asc" offset="2" limit="1"}
  <img src="/images/site_images/{parents:filename}" />
 {/parents}   
{/exp:channel:entries}
       
meatpaste's avatar
meatpaste
16 posts
5 years ago
meatpaste's avatar meatpaste

I would try using the ‘count’ property, that way you only run 1 parents tag (less db overhead anyway).

{if parents:count == "1"}
  First Row HTML
 {if:else}
  Other HTML
    {/if}
       
eloyer17's avatar
eloyer17
8 posts
5 years ago
eloyer17's avatar eloyer17

Thanks—unfortunately I don’t think that will work in my case because these elements are nested in a structure that I don’t want to repeat. I don’t believe I can get to the structure below by enclosing the whole thing in a {parents} tag and then using the count parameter because then the outermost divs would get repeated.

FYI this is from an EE 1.6.0 template that I’m porting to EE 5. In the original template, I was able to use {reverse_related_entries} with this structure and it worked.

<div>
  <div>
    1st project image
  </div>
  <div>
    2nd project image
  </div>
</div>
<div>
  <div>
    3rd project image
  </div>
  <div>
    4th - nth project images
  </div>
</div>
       
meatpaste's avatar
meatpaste
16 posts
5 years ago
meatpaste's avatar meatpaste

that looks like a good candidate for the switch tag eg.

{if parents:count == "1"}<div>{/if}
{parents:switch="||</div><div>"}
CONTENT
{if parents:count == parents:total_results}</div>{/if}
       
eloyer17's avatar
eloyer17
8 posts
5 years ago
eloyer17's avatar eloyer17

I think I understand how that would work. My real div tags would have attributes, however—how would I go about escaping the quotes in those?

       
meatpaste's avatar
meatpaste
16 posts
5 years ago
meatpaste's avatar meatpaste

Use singles quotes?

       

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.