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 to show content only if it exists

July 03, 2007 12:17pm

Subscribe [2]
  • #1 / Jul 03, 2007 12:17pm

    SNE

    18 posts

    In the following example, I am getting custom field data to show correctly, but at the end of the entries, I get an extra “[]”, as shown below. How would I use a conditional (or would I) to make sure that info is displayed only if it exists for a custom field?


    CODE:

    <table>
    {exp:weblog:entries}
    <tr>
    <td colspan=“2”>{fitness_article_title}</td>
    </tr>
    <tr>
    <td colspan=“2”>{fitness_article_intro}</td>
    </tr>
    <tr>
    <td align=“left”>[{fitness_article_source}]</td>
    <td align=“right”>{fitness_article_url}</td>
    </tr>
    {/exp:weblog:entries}
    </table>


    RESULTING OUTPUT:

    Title

    Intro goes here.Intro goes here.Intro goes here.Intro goes here.Intro goes here.Intro goes here.Intro goes here.Intro goes here.Intro goes here.Intro goes here.Intro goes here.Intro goes here.Intro goes here.Intro goes here.Intro goes here.Intro goes here.Intro goes here.Intro goes here.Intro goes here.Intro goes here.

    [source: ]http://www.source.com]  http://www.yahoo.com


    Title2

    Intro goes here.Intro goes here.Intro goes here.Intro goes here.Intro goes here.Intro goes here.Intro goes here.Intro goes here.Intro goes here.Intro goes here.Intro goes here.Intro goes here.Intro goes here.Intro goes here.Intro goes here.Intro goes here.Intro goes here.Intro goes here.Intro goes here.Intro goes here.

    [source: ]http://www.source2.com]  http://www.google.com


    []  <——————- this is shown below the final entry and should not be there.

  • #2 / Jul 03, 2007 12:58pm

    DSite

    18 posts

    Without knowing what your entries are, it’s a little hard to understand why you’d end up with the extra brackets, but you can definitely accomplish what you want to do with conditionals.

    You could try this:

    {if fitness_article_source != ""}
    [{fitness_article_source}]
    {/if}

    or this:

    {if fitness_article_source}
    [{fitness_article_source}]
    {/if}

    More helpfulness about conditionals can be found here.

  • #3 / Jul 04, 2007 10:19am

    SNE

    18 posts

    Thank you…this did the trick.

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

ExpressionEngine News!

#eecms, #events, #releases