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.

Issues using if statements to check if file exists

September 20, 2012 1:18pm

Subscribe [2]
  • #1 / Sep 20, 2012 1:18pm

    jsuissa

    147 posts

    We have a field field for vcards and we want to use conditionals to check if each user has specified a file.

    We’ve tried both examples below and nothing shows up even when a file has been selected for that user.

    Any help pointing us in the right direction is much appreciated.

    {if people_vcard != ""}
    <a href="http://{people_vcard}">Vcard</a>
    {/if}
    {if people_vcard}
    <a href="http://{people_vcard}">Vcard</a>
    {/if}
  • #2 / Sep 20, 2012 1:49pm

    Stephen Callender

    148 posts

    What happens when you isolate the field {people_vcard} for a user with a file? Are you getting anything?

    What are the other ee tags you have surrounding this?

  • #3 / Sep 20, 2012 1:53pm

    jsuissa

    147 posts

    Without the if statement the field appears and works properly. The conditional is the issue.

    We have quite a bit of code around it, including other fields that are working well.

    Below is a larger sample:

    {related_entries id="people_office"}
            <span>{title}</span>
    
             {office_address}
             Tel {office_phone}
    
             Fax {office_fax}
            
            {/related_entries}
            <a href="mailto:{people_email}">{people_email}</a>
    
            {if people_vcard}
            <a href="http://{people_vcard}">Vcard</a>{/if}
     
            
           </div>
           {people_bio}
  • #4 / Sep 20, 2012 1:58pm

    Stephen Callender

    148 posts

    Gotcha. And everything else between the if statement is showing? Anchor and “Vcard” copy? But just not the file itself?

    What if you tried

    {if '{people_vcard}' != ''}<a href="http://{people_vcard}">Vcard</a>{/if}
  • #5 / Sep 20, 2012 2:02pm

    jsuissa

    147 posts

    Thanks for the help on this. No luck on that example, now the vcard appears for every users bio even when they don’t have one specified.

    This is the only part that doesn’t show, everything else in the larger chunk of code is working properly:

    <a href="http://{people_vcard}">Vcard</a>
  • #6 / Sep 20, 2012 2:04pm

    Stephen Callender

    148 posts

    What’s the channel:entries tag or larger tag you have around this?

  • #7 / Sep 20, 2012 2:05pm

    jsuissa

    147 posts

    Sure:

    {exp:channel:entries channel="people" limit="1"}
  • #8 / Sep 20, 2012 2:08pm

    Stephen Callender

    148 posts

    Hmm. *scratching head*
    Does the same thing have if you put an if statement around another field?

  • #9 / Sep 20, 2012 2:13pm

    jsuissa

    147 posts

    Yea…same here. So I just tried a conditional on the e-mail field and it worked.

    I think this issue has something to do with the fact the field type is a file.

  • #10 / Sep 20, 2012 2:15pm

    Stephen Callender

    148 posts

  • #11 / Sep 20, 2012 2:28pm

    jsuissa

    147 posts

    Yea, I’m pretty sure it’s a bug. Thanks for all the recommendations on this. I’m using 2.52 so my field didn’t match what was specified in the bug fix so I left it as is.

    Even tried reversing the approach, and that doesn’t work:

    {if people_vcard == ''}{if:else}
    <a href="http://{people_vcard}">Vcard</a>{/if}

     

  • #12 / Sep 20, 2012 2:30pm

    Stephen Callender

    148 posts

    That sucks. Good luck and I’m sure you’ll get it up sooner than later.

  • #13 / Sep 24, 2012 1:42am

    Kevin Smith

    4784 posts

    Thanks for tossing in to help, Stephen!

    jsuissa, one of your first examples is the correct syntax, and it should work:

    {if people_vcard}
    <a href="http://{people_vcard}">Vcard</a>
    {/if}

    Just to make sure we’re on the same page here, could you update to EE 2.5.3 and give that conditional syntax a try? If it doesn’t work, let me know what the output is instead.

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

ExpressionEngine News!

#eecms, #events, #releases