EE 5.2.2
I have a homepage
channel with a primary entry that handles a bunch of stuff on the homepage. One of the things it has is a relationship field called featured movie
that can have just one of any entries in the movie
channel set to it.
What I am trying to do in my template is
- check if there is a featured movie set and then
- check if that featured movie has a video id set to it. If it does, display a carousel with an image and a YouTube embed, if not just show the image.
Here's how the section looks.
{exp:channel:entries channel="homepage" limit="1"}
{if featured_movie}
<div class="series_program_section w-16">
<div class="w-8">
<h2>Featured</h2>
<a href="/calendar/movie/{featured_movie:url_title}" style="text-decoration: none;">
<h3>{featured_movie:title}</h3>
<div class="links_container">
<a href="/calendar/movie/{featured_movie:url_title}">Explore this movie</a>
</div>
</a>
</div>
<div class="w-8">
{if featured_movie:video_id != ''}
<section class="carousel">
<div class="owl-example owl-carousel">
<div class="item">
<img class="main_image" src="{featured_movie:image}" alt="{featured_movie:title} image">
</div>
<div class="item">
<iframe width="100%" height="315" src="https://www.youtube.com/embed/{featured_movie:video_id}" frameborder="1" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture"></iframe>
</div>
</div>
</section>
{if:else}
<img class="main_image" src="{featured_movie:image}" alt="{featured_movie:title} image">
{/if}
</div>
</div>
{/if}
{/exp:channel:entries}
To me, this looks like it should work just fine. But what's happening is that {if featured_movie:video_id != ''}
is always returning false even when there is a video_id
set. I have tested this by putting {featured_movie:video_id}
before the conditional and watching the id render on the page but not return the code for when that condition is true.
I've tried other options for the conditional such as {if featured_movie:video_id:count == 1}
and {if featured_movie:video_id:no_results}
and none of them seems to work.
What am I missing? Is there some special way of doing conditionals for the fields in a relationship entry?