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

Output dynamic grid row from a related entry

How Do I?

Tom_Watney's avatar
Tom_Watney
18 posts
9 years ago
Tom_Watney's avatar Tom_Watney

I’m looking to pull in a specific grid row from a related entry, whereby the row is specified by a field on the parent entry:

Parent entry
 Relationship
 Custom_Field
 
Child entry
 grid_field
  Row 1
  Row 2
  Row 3

I’ve been trying to make this work with row_id without success.

{exp:channel:entries channel="channel_name"}

{preload_replace:set_row_id="
{if Custom_Field == "One"}1
{if:else Custom_Field == "Two"}2
{/if}
"}


 {relationship:grid_field row_id="{set_row_id}"}
  {relationship:grid_field:field}
 {/relationship:grid_field}

{/exp:channel:entries}

I think it is because it is not possible to pull in dynamic parameters because of the parse order.

I have tried using basic PHP and embed without any luck.

How else could I achieve this goal?

v:2.11.2

       
Rob Allen's avatar
Rob Allen
3,105 posts
9 years ago
Rob Allen's avatar Rob Allen

I’m not sure that preload_replace will work inside an entries tag.

Have you tried hard coding the row ID to see if that works:

{exp:channel:entries channel="channel_name"}
    {relationship:grid_field row_id="1"}
          {relationship:grid_field:field}
     {/relationship:grid_field}
{/exp:channel:entries}
       
Tom_Watney's avatar
Tom_Watney
18 posts
9 years ago
Tom_Watney's avatar Tom_Watney

Hi Rob,

Thank you for your reply. Hardcoding the row_id is fine and pulls in the right data. My goal was to make this dynamic so the row_id is set by a field on an entry.

Though not ideal, I have found a workaround which use {segment_id} which does render within the channel tag parameters as it gets parses sooner.

       
Rob Allen's avatar
Rob Allen
3,105 posts
9 years ago
Rob Allen's avatar Rob Allen

Yep segment ID will work, you could also use real numbers instead of One, Two etc. in your custom field

Custom text field, ie my_number_field, and populate with a real number like, 1,2,3 etc then call the field value into the relationship tag:

{exp:channel:entries channel="channel_name"}

 {relationship:grid_field row_id="{my_number_field}"}
  {relationship:grid_field:field}
 {/relationship:grid_field}

{/exp:channel:entries}

That should work, if all else fails you could put the relationships tag into an embed and pass the number through that way.

       

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.