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

Display Program from relationship field

How Do I?

Trevzilla's avatar
Trevzilla
15 posts
one year ago
Trevzilla's avatar Trevzilla

I have a channel called {calendar_events} in which there are several fields, including {short_title}, {additional_comments} and a relationship field called {program}

See attached.

In my template if I write:

{calendar:short_title}

The short_title is displayed correctly.

The same is true if I write:

{calendar:additional_comments}

But if I write:

{calendar:program}

Nothing displays. I would expect it to display the title of whichever program is selected in the relationship field.

How can I get that title to display?

       
Rob Allen's avatar
Rob Allen
3,105 posts
one year ago
Rob Allen's avatar Rob Allen

As you are only allowing one relationship use {calendar:program:title}.

       
Trevzilla's avatar
Trevzilla
15 posts
one year ago
Trevzilla's avatar Trevzilla

It’s the weirdest thing. When I try that it literally prints out “{calendar:program:title}” on the webpage.

       
Rob Allen's avatar
Rob Allen
3,105 posts
one year ago
Rob Allen's avatar Rob Allen

Ah I see, try this test channel entries code, it should output each field value (where it exists):

{exp:channel:entries channel="calendar_events"}
  {title}

  {short_title}

  {additional_comments}

  {program:title}

{/exp:channel:entries}
       
Trevzilla's avatar
Trevzilla
15 posts
one year ago
Trevzilla's avatar Trevzilla

That seems to work…except like you said it is outputting each field value, so I am now getting a huge list of Program Titles from the entire calendar_events channel. How do I make it so it only displays the one Title that is selected in the relationships field?

       
Rob Allen's avatar
Rob Allen
3,105 posts
one year ago
Rob Allen's avatar Rob Allen

You’ll need to add a limit parameter to the channel entries tag, e.g. {exp:channel:entries channel="calendar_events" limit="1"}

       
Trevzilla's avatar
Trevzilla
15 posts
one year ago
Trevzilla's avatar Trevzilla

This is great! I’m closer than I’ve ever been before. Thank you for your help so far!

With that said, the limit=”1” solution is always returning the first entry in the calendar_events channel. The program selected in the relationships channel won’t always be the first entry.

Any tricks up your sleeve to make it respect the selection made in the relationships field and return the title associated with that selection?

edit* - I’m looking at it a bit closer, and it turns out it’s not bringing up the first Program in the channel. It’s always bringing up our “Family Engagement” program, which doesn’t have the lowest ID#, and is not the first alphabetically. I have no idea why it’s selecting Family Engagement as the 1 entry to display. But regardless, it’s not respecting the selection made in the relationship field.

edit2* - It’s looping through the calendar_events channel…not the programs channel. And it’s bringing up the title of the program selected in the newest calendar_event entry for all entries.

       
Rob Allen's avatar
Rob Allen
3,105 posts
one year ago
Rob Allen's avatar Rob Allen

The code example lists entries from your calendar_events channel that relates to a Program.

If you wanted to list all Programs (or just one) you’d call that channel, for example if your Programs channel has a short name of “programs” and the relationship field of “program”:

{exp:channel:entries channel="programs" limit="1"}
  
  <!-- Program title-->
  {title}

  <!-- calendar_events that relate to this program -->
  {parents field="program"}
    {parents:title}
  {/parents}

{/exp:channel:entries}
       
Trevzilla's avatar
Trevzilla
15 posts
one year ago
Trevzilla's avatar Trevzilla

Thanks you for all your help. I just found out this isn’t going to work. This gem was found deep within the calendar add-on documentation:

“For performance reasons (due to the recurrence rule functionality where we have to “inflate” event results in the template tags), Calendar uses its own rewritten version of the Channel:Entries functionality. The trade-off here is that more advanced fields like Grid, File, Relationship, etc will not work or have limited functionality:

Currently the Relationship fieldtype will not parse inside any Calendar template tags. We hope to restore some functionality for this in the future.”

       

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.