ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Conditional not working properly (relationships involved).

September 02, 2011 10:14am

Subscribe [2]
  • #1 / Sep 02, 2011 10:14am

    Hello

    We have been trying to get this conditional working for a while now and I’m having no luck whatsoever. Quick background info:

    We have a flash MP3 player on our article pages. It pulls the source MP3 from another entry using a relationship field (called ‘podcast_episode’). In the code below you can see it looks for the related entry then pulls in the {mp3} custom field (an ngen file upload field URL).

    We changed this system recently and simply put an ngen file upload custom field called {mp3file} within the article entry page itself so we don’t have to use relationships anymore.

    Now we have half of our entries using the old system and the new. Ideally we would like a conditional to display the correct information depending on whether a relationship is being used or not.

    Here is the latest code I have tried but it doesn’t appear to be working. It only works if the Relationship method is being used and an entry is picked. Not if there is NO relationship entry selected and the new {mp3file} field is used instead.

    {if mp3file}
    {exp:lg_replace:haystack needles="player"}
                        
                        {exp:lg_replace:replacement needle="player"}
                            [removed][removed]
                            <object type="application/x-shockwave-flash" data="{site_url}audio/player.swf" id="audioplayer1" height="24" width="290">
                            
                            
                                                     {/related_entries}
                            
                            
                            
                            </object>
                                                    
      
    {/exp:lg_replace:replacement}
    {if:else}
    {exp:lg_replace:haystack needles="player"}
                        
                        {exp:lg_replace:replacement needle="player"}
                            [removed][removed]
                            <object type="application/x-shockwave-flash" data="{site_url}audio/player.swf" id="audioplayer1" height="24" width="290">
                            
                            {related_entries id="podcast_episode"}
                            
                            {/related_entries}
                            
                            
                            
                            </object>
                                                    
      
    {/exp:lg_replace:replacement}
    {/if}

    ExpressionEngine 1.7.1 - Build:  20110520

    Cheers
    Uncommon Knowledge

  • #2 / Sep 02, 2011 11:45pm

    Kevin Smith

    4784 posts

    Hi Uncommon Knowledge,

    One thing I would recommend is to simplify the conditional with mp3file. Right now it includes an if:else, which causes the conditional to be parsed much later in the template parse order (notably, after modules and plugins). If you made it a set of simple conditionals, they would be parse before the module tags. So something like…

    {if mp3file}
    {exp:lg_replace:haystack needles="player"}
                        
                        {exp:lg_replace:replacement needle="player"}
                            [removed][removed]
                            <object type="application/x-shockwave-flash" data="{site_url}audio/player.swf" id="audioplayer1" height="24" width="290">
                            
                            
                                                     {/related_entries}
                            
                            
                            
                            </object>
                                                    
      
    {/exp:lg_replace:replacement}
    {/if}
    {if mp3file == ''}
    {exp:lg_replace:haystack needles="player"}
                        
                        {exp:lg_replace:replacement needle="player"}
                            [removed][removed]
                            <object type="application/x-shockwave-flash" data="{site_url}audio/player.swf" id="audioplayer1" height="24" width="290">
                            
                            {related_entries id="podcast_episode"}
                            
                            {/related_entries}
                            
                            
                            
                            </object>
                                                    
      
    {/exp:lg_replace:replacement}
    {/if}

    If that doesn’t help, you may need to further simplify your template, even removing third-party modules like LG Replace for troubleshooting purposes.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases