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.

Custom fields and conditionals.

March 29, 2010 9:01pm

Subscribe [2]
  • #1 / Mar 29, 2010 9:01pm

    danyels0n

    16 posts

    Hi everyone, I’ve looked all over, and I cant figure this one out, so I turn to you!

    I would like to have color thumbnails that only display if the color is in stock.

    Is there a way to create a conditional that calls data from a “checkbox” custom field?

    I began with:

    {if product_color !=""}
    
    success
    
    {/if}

    _______

    This works (pulls up “success”), but is there a way to use a conditional to replace the color “blue” with “success” but leave the others alone?

  • #2 / Mar 29, 2010 10:23pm

    JArment

    131 posts

    Does this work for you?

    {if product_color == "blue"}
    {product_color}
    {/if}
  • #3 / Mar 29, 2010 11:06pm

    danyels0n

    16 posts

    I realized that != is a not equal tag (noob) and I tried this, but it still doesn’t work.

    Here is what I’ve tried (and failed with) so far :

    <div id="viewcontent">
                <div id="content-data">
                <!-- Begin CONTENT TITLE -->
                {exp:weblog:entries weblog="products" limit="1"}
                    <div id="data-title">
                        <h4>{title}</h4>
    <p>                    </p><h5>{product_price}</h5>
    <p>                {product_body}<br />
                    </div><br />
                <!-- Begin CONTENT SIZE --><br />
                <div id="data-size"><br />
                        {product_size}<br />
                    </div><br />
                <!-- Begin CONTENT COLOR --><br />
                <div id="data-color"><br />
                        {if product_color == "Black"}<br />
                {product_color}<br />
                {/if}<br />
                    </div><br />
                <!-- Begin CONTENT QUANTITY--><br />
                <div id="data-quantity"><br />
                        {product_quantity}<br />
                    </div><br />
                <!-- Begin CONTENT ADD TO CART --><br />
                <div id="data-cart"><br />
                        Add to cart<br />
                    </div><br />
                </div>

    Any ideas?

  • #4 / Mar 29, 2010 11:08pm

    danyels0n

    16 posts

    To clarify, I also tried :

    <div id="data-color">
                    {if product_color == "Black"}
                SUCCESS
                {/if}
                    </div>

    To no success. :(

  • #5 / Mar 30, 2010 12:25am

    JArment

    131 posts

    Whenever I work with conditionals, I like to see what a variable is outputting. If you put:

    {product_color}

    ... you will see what the value of product color. It may be “black” instead of “Black”, you know what I mean. So test what each variable is outputting and then put that in your conditional instead. Because the conditionals are case-sensitive.

  • #6 / Mar 30, 2010 2:26am

    danyels0n

    16 posts

    {product_color}

    pulls up the color list just fine.

    The end goal is to allow my client to click the available colors (with checkboxes) for a t-shirt when creating an entry, and have it display a thumbnail.

    So if I have Black, Blue, Red, etc, is it possible to isolate each of these titles and display the appropriate thumbnail?

    Maybe there’s a smarter way of going about this?

    Thank you for your response!

  • #7 / Mar 30, 2010 10:57am

    JArment

    131 posts

    Could you use CSS?

    <span class="color_tab {product_color}">
        {product_color}
    </span>

    CSS:

    .color_tab {
        display: block;
        height: 40px;
        text-indent: -9999px;
        width: 40px;
    }
    .blue { background-color: blue; }
    .black { background-color: black; }
    .red { background-color: red; }

    But you’ll have to get the conditionals to work. Do you have those working now?

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

ExpressionEngine News!

#eecms, #events, #releases