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.

Problems with conditional statement and file field

September 24, 2013 2:13pm

Subscribe [1]
  • #1 / Sep 24, 2013 2:13pm

    cballenar

    4 posts

    Hey,
    I’ve been researching the web for a few hours and trying multiple things with no luck.
    One of my custom fields is a cover image and I’m trying to define how the output is going to look based on the category of the entry.

    Here’s my code:

    {!-- If entry has Cover --}
    {if entry_cover}
     <div class="cover">
     {categories}
      {if category_id == '2'}
       {entry_cover}
        <a href="http://{page_url}">{path}_xlo/{filename}.{extension}</a>
       {/entry_cover}
      {if:else}
       {entry_cover}
        <a href="http://{page_url}">{path}_xl/{filename}.{extension}</a>
       {/entry_cover}
      {/if}
     {/categories}
     </div>
    {/if}

    The problem is that the “else” statement isn’t working. When there’s no image it will simply ignore everything. Is there a problem with including a field multiple times? If so is there a workaround?

    I also tried the following syntax with no luck:

    {!-- If entry has Cover --}
    {if entry_cover}
     <div class="cover">
      {entry_cover}
       <a href="http://{page_url}">_      <a href="_         {path}_         {categories}_         {if category_id == 8GvF9n3wHCcx2Docrpb3kACYrsYvLeeatypography_img_src_end2} _xlo/ {if:else} _xl/ {/if}_         {filename}.{extension} tag={url_title} ">_         {path}_         {categories}_         {if category_id == 8GvF9n3wHCcx2Docrpb3kACYrsYvLeeatypography_img_src_end2} _xlo/ {if:else} _xl/ {/if}_         {filename}.{extension} tag={url_title} </a>_   </a>
      {/entry_cover}
     </div>
    {/if}

    This results in {entry_cover}{/entry_cover} being showed as text with an <img> tag with no source.

    Any suggestions?

    EDIT: It looks like some of the characters in my second code sample were being escaped. Had to add some spaces and line breaks to avoid this. There are no spaces or line breaks in the <img> tag.

  • #2 / Sep 25, 2013 9:52am

    cballenar

    4 posts

    I was able to solve this using stash.

    Apparently the problem was in having a field called twice. Can someone explain why this is a problem or point me in the direction to find the answer?

    Thanks.

  • #3 / Sep 25, 2013 9:53pm

    cballenar

    4 posts

    False alarm, the stash variable wasn’t even working. still trying to figure out a way to make this work. Anyone?

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

ExpressionEngine News!

#eecms, #events, #releases