Module, Plugin

Developer
Supported

Rest

ExpressionEngine 2

Back to this add-on's main page
View Other Add-ons From Phil Sturgeon

     

You must be logged in to post.

Performing Conditional Test on Nested Field

Support Request

uuitservices
uuitservices

Hello,

I am working on a site that is using REST to pull an RSS feed for a calendar.  This RSS feed has an image URL nested inside and enclosure element.  I need to perform a conditional IF statement on the nested element but I am struggling on how to do it properly.  Not sure if this is an issue with expression engine or not.  I am really just looking to see if you had any ideas on how to do this.  Here is my code sample:

{exp:rest name="featured_events_feed" limit="25"}
    {enclosure}{if url 
!= ""}<img src="{url}{/enclosure}" alt="{title}" width="100px" height="100px" border="0" />
    
{if:else}{/enclosure}<img src="/assets/images/sac_state_logo_event.png" alt="{title}" width="100px" height="100px" border="0" />
    
{/if}      
                            
<h3>{pubDate format="%F %j, %Y"}</h3>
                            <
h4><a href="{link}">{title}</a></h4>
                            <
div ></div>
      
{/exp:rest} 

So for me to be able to test the conditional against whether or not the field URL is empty I have to wrap it with the parent element enclosure.  The output of this test works great when the URL element has something in it but when I get to the ELSE statement it does work in the sense that it puts up the image to replace it but it does not properly close the enclosure tag.  on my HTML out I get what you see in the attached screenshot.  The “Choirs” event is the error and the event above that is a working one.

Here is the link to the RSS feed I am referencing

RSS Feed

Any thoughts?

Thanks!