Background:
I’m working on a blog that can add a video and a header image, but the video is optional. The header image shows on the blog list page. On the blog post page, both the header image and the video show. However, I only want the video to show if there is a video present. If there is no video present, I want to show the header image.
Pseudo-Code to explain:
if(exists(video)) {
print "<video embed>";
} else {
print "header.jpg";
}In Expression Engine:
I can test if the image exists, but the moment I move it into the video section, the value gets overridden and no longer usable. I’ve looked up ways to set a variable and maintain the scope later, but all the solutions I’ve seen so far give me a solution in PHP. I need a native EE solution for this, and I’m sure there must be one.
So I had attempted to prepare the code like this:
{exp:playa:children field="blog_video"}
{if no_children}
{postImage}
{exp:ce_img:single src="{url}" width="550" class="post_image" title="{title}"}
{/postImage}
{/if}
{exp:channel_videos:videos entry_id="{entry_id}" embed_width="570" embed_height="366"}
{if video:no_videos}
{postImage}
{exp:ce_img:single src="{url}" width="550" class="post_image" title="{title}"}
{/postImage}
{/if}
{if video_image}
<div class="youtubeSwap">
<div class="imageHolder">
{video_image}
</div>
<div class="youtubeHolder" >
{/if}
<div class="in_page_video_holder">
{video:embed_code}
</div>
{if video_image}
</div>
</div>
{/if}
{/exp:channel_videos:videos}
{/exp:playa:children}But what would happen is that the header image would not show and instead write: {postImage}{/postImage}
What can I do to extend the scope of the {postImage} value, or otherwise find a method to post the video in replacement of the header image, when applicable?