ExpressionEngine 7.5 has been Released! Learn More!
I have a channel that is used for Calendar Entries. The calendar entries are events that our various programs are hosting. I’d like to make it so that when we are creating a new event, it’ll link to the program page. So in the calendar channel, I’ve added a relationships field, that is a relationship to the programs channel. All this seems to be working.
My issue is with the templates. I can’t seem to figure out how to pull the url_title from the programs channel that is linked to in the relationship field.
Here’s a snippet of my code:
(I can’t seem to give my code snippets without triggering an error on this forum The forum keeps giving me spam errors when attempting to give code examples.)
Everything in this code works except at the very bottom where I am saying {if calendar:program_link!=""}
Essentially, I would love to replace the <a href="http://{path=calendar/redirect}/{calendar:url_title}/">{if calendar:short_title}{calendar:short_title}{if:else}{calendar:title}{/if}</a>
line so that it isn’t going to the calendar/redirect page. It’s just linking to the program page that is selected in the relationship field.
I hope that’s clear enough, and I’m happy to expand if it doesn’t make sense. I’m super confused here though!
Oh- I bet the spam filter is kicking in because of the links- you have too many, it will trigger it.
And yes- relationship fields can be tricky!
> Everything in this code works except at the very bottom where I am saying {if calendar:program_link!=""}
If it’s all good except for the conditional? You may be hitting this weird issue relationships and conditionals. Check out the docs on conditionals, specifically bracing. See if it works like this:
{if '{calendar:program_link}' != ""}
IF you know that program link variable shouldn’t have any single quotes in it, you should be ok. Let’s see if that makes it work. Or maybe I’m not fully understanding what’s up!
Thank you for the reply. I apologize about the crummy post above. It’s super unclear because of that spam filter.
I just need to create a link. It seems like it should be super easy.
I have a programs channel with a url_title field in it.
I need to append that url_title field to the end of a link. The url_title is selected via a relationships field.
In screenshot1 is the program entry. Essentially the entry that creates a page that I want to link to. screenshot2 is the top of the calendar entry page. screenshot3 is the relationship field.
In my template, how do I pull the url_title from the programs page, while I’m “in” {calendar}?
{calendar:program_link:url_title} seems intuitive to me, but it doesn’t seem to work that way.
Here, I’ll just upload screenshot of some of my code.
I feel like something like this should work, but I’m just not quite familiar enough to know how to call fields with relationships.
In this screenshot, the upper <a > tag works flawlessly. It’s the lower one on line 91 that doesn’t work.
So I almost understand, but… maybe add a bigger screenshot from the template?
The part where I get confused- {calendar:program_link} so what is calendar? Is it the shortname of your relationship field? Or is perhaps the shortname of a grid field and the relationship field is also in the grid?
This is what I imagine to be going on, given the variables.
{calendar} {!– grid field}
{calendar:some_text} {!– some text field/column in the grid}
{calendar:program_link:url_title} {!– program_link is a relationship field in the calendar grid}
{/calendar} {!– close the grid field}
IF those assumptions are correct- I’d actually expect that to work- assuming the relationship field is a single relationship.
If it is NOT in a grid, program_link IS the shortname of the relationship field, then just {program_link:url_title} should work for a single relationship field.
But the calendar prefix is in there for some of your code and sounds like it’s working, so… I’m still fuzzy on the template.
Maybe do a REALLY simple test template with just the variables in question on it, see if it works, and if not, shoot over a screen shot.
And the examples in the docs are pretty solid, so giving those a double check won’t hurt.
Feels like you must be close to having it solved, but I still don’t quite grok what’s happening.
Alright, I think you’re on the right track.
Attached is a screen shot of more code. Again, it’s all working except at line 92. In the screen shot. the words URL-> print to the webpage. If I change the variable on line 92 to {calendar:url_title} it appropriately displays the URL Title from the Calendar Events channel.
If the variable says {calendar:program_link} nothing displays.
If the variable says {calendar:program_link:url_title} it actually prints that entire string to the screen.
program_link is the short title of the relationship field.
I think like you say I just need to get that variable to read properly.
(It’s all super confusing, because Calendar is a third party app, we have a field called calendar that is a “calendar” type.) We also have a CHANNEL called “Calendar Entries”. Maybe that’s part of the issue)
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.