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.

Having trouble getting the {count} variable to work!!

March 31, 2011 4:43am

Subscribe [4]
  • #1 / Mar 31, 2011 4:43am

    slimboyfatz35

    31 posts

    Hi folks,

    Currently working on a client site which as a list of product items - Item name, Price and Image (with popup window on hover)

    They are running a special offer on certain products with a reduced price, so I want to show this on certain products with a simple ‘line-through’ the price. Now I have used the {if segment_*} on the actual single items pages to show the reduced price field no probs.

    Obviously I cant do this on the listings page as they are all sat on the same segment (co.uk/products), so I thought I would try the {count} variable to target specific entries on that page….but I’ll be damned if I can get it to work!!

    Really need some advice on this folks :( I have popped the snippet of code I currently have for testing purposes -

    <div class="c-f">
                                <ul id="tooltips">
                                    {exp:channel:entries category="{segment_to_category_id}" channel="bras" orderby="reorder" sort="asc" disable="categories|category_fields|member_data|pagination|trackbacks" dynamic="no" rdf="off"}
                                        <li>
                                            <span class="tooltip product{count}">
                                                {product_image_tooltip}
                                                <strong class="tooltip-title">{title}</strong>
                                                <span class="tooltip-colours">
                                                    <span class="s-h-o"> Colours:</span> Available in {product_colours}{if {row_count} == {total_rows}} and {if:elseif {row_count} != 1}, {/if}{colour_name}{/product_colours}
                                                </span>
                                                {if count == '1'}
                                                A Reduced Price
                                                {if:else}
                                                <span class="tooltip-price">£{product_price}</span>
                                                {/if}
                                                {if product_featured_message} <span class="tooltip-message">{product_featured_message}</span>{/if}
                                            </span>
                                        </li>
                                    {/exp:channel:entries}
                                </ul>
                            </div><!-- .c-f -->
  • #2 / Mar 31, 2011 7:05am

    Mark Bowen

    12637 posts

    Before trying to figure out what’s wrong here why would you want to use the {count} variable to show some items as special offers?

    If you have a new entry then the count is going to be different each time and so different items are going to get shown as a special offer surely?

    I don’t know how you have your channel fields etc… set up but I would personally have a drop-down field in the channel entries with a simple No / Yes option to it.

    (Make sure to put the No first as that way when you create each entry they don’t all get set to Yes as default.)

    That way when you create an entry you have an option as to whether it should be shown the way you want or not.

    You can then just do this in your template code :

    {exp:channel:entries
        channel="bras"
        orderby="reorder"
        dynamic="off"
        sort="asc"
        disable="member_data|pagination|categories"}
    
    {if discounted == "Yes"}
    …Show discounted html here…
    {if:else}
    …Show normal price here…
    {/if
    {/exp:channel:entries}

    (Sorry I simplified the code above for sake of ease but it should go into your example as well)

    Best wishes,

    Mark

  • #3 / Mar 31, 2011 8:37am

    slimboyfatz35

    31 posts

    Hi Mark,

    Will give what you mentioned a try. The reason I used count was that the entry (with reduced price) was always going to stay 1st in the order so {count ==1} would always stand.

    thanks

    Marc

  • #4 / Mar 31, 2011 8:58am

    Mark Bowen

    12637 posts

    Hi Marc,

    I still think it would be best in this instance to go with something a bit more forgiving 😉

    If someone ever adds a new entry then it’s all going to get messed up. Should still work with the count variable though. Not too sure why it’s not in this case. Perhaps if you bring down the code in your entries tag to the absolute bare minimum and see if it works or not :

    {exp:channel:entries
    
    category="{segment_to_category_id}"
    channel="bras"
    orderby="reorder"
    sort="asc"
    disable="categories|member_data|pagination|trackbacks"
    dynamic="no"
    rdf="off"}
    
    {if count == "1"}
    A Reduced Price
    {if:else}
    {product_price}
    {/if}
    
    {/exp:channel:entries}

    If that works then you know the problem lies elsewhere. If it doesn’t then we’d need to look in more detail as to what’s going on. Also above in the code I’ve posted I took out category_fields in your disable=”“ parameter as I’m fairly certain that if you place categories into the parameter then the category_fields are by default not brought back anyway. Just saves a little typing I guess? 😉

    Best wishes,

    Mark

  • #5 / Mar 31, 2011 5:06pm

    Sue Crocker

    26054 posts

    Thanks for the assist, Mark.

    SBF: (Marc) - I’d do what Mark suggested, using a custom field with the default value of No, then testing for it. Make sense?

  • #6 / Apr 01, 2011 5:11am

    slimboyfatz35

    31 posts

    Yup, tried what Mark mentioned above, works great! A more robust way of doing things methinks! 😊

    thanks again.

  • #7 / Apr 01, 2011 6:20am

    Mark Bowen

    12637 posts

    Yup, tried what Mark mentioned above, works great! A more robust way of doing things methinks! 😊

    thanks again.

    There are many ways to crack a cookie with ExpressionEngine but yep I think that way will give you more power in the long run.

    Glad you have it all working now though.

    Hope everything else goes well for you.

    Best wishes,

    Mark

  • #8 / Apr 04, 2011 4:05am

    John Henry Donovan

    12339 posts

    Thanks again Mark. Feel free slimboyfatz35 to start a new thread if you have any more questions

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

ExpressionEngine News!

#eecms, #events, #releases