Problems, need help? Have a tip or advice? Post it here.
5 posts Page 1 of 1
Hi,

If I have a list of DIV containers in HTML and the last container has a class of 'last', how can I use the IF statement to add the class?

This is some basic HTML code to illustrate my question:

Code: Select all
<div class="box1">
    <p>Some content</p>
</div><!--end box1-->

<div class="box1">
    <p>Some content</p>
</div><!--end box1-->

<div class="box1 last">
    <p>Some content</p>
</div><!--end box1-->


The last DIV contains an additional class of 'last'.

Any thoughts?

Many thanks,

G.
Hi,

I assume that you are generating the list of divs using some Couch tag that repeats its contents - typically the 'pages' tag.
If so, please paste in your code that is creating these multiple divs and I'll try and show you how that 'last' div can be handled.
Hi,

Here is the requested code:

Code: Select all
<cms:pages masterpage='gig_list.php'>
            <div class="gig_list_box">
               <div class="gig_date">
                   <h3><cms:show k_page_title /></h3>
                    <h4><cms:show gig_date /></h4>
                </div><!--end gig_date-->
                <div class="gig_details">
                    <ul>
                        <li><span>Venue:</span><cms:show gig_venue /></li>
                        <li><span>Time:</span><cms:show gig_time /></li>
                        <li><span>Tickets:</span>&pound;<cms:show gig_tickets /></li>
                        <li class="last"><span>Info:</span><a href="<cms:show gig_website />"><cms:show gig_info /></a></li>
                    </ul>
                </div><!--end gig_details-->
            </div><!--end gig_list_box-->
            </cms:pages>


The opening DIV 'gig_list_box' will contain the extra class of 'last' if it is last in the repeated list.

Thanks for your help!

G.
Hi,

You can check for the 'k_paginated_bottom' that gets set for the last element in the loop.
The revised code now becomes -
Code: Select all
<cms:pages masterpage='gig_list.php'>
            <div class="gig_list_box <cms:if k_paginated_bottom>last</cms:if>">
            ....
            </div>
</cms:pages>

This aside, in the 'pages' loop you are using, I think you'll also want to set a 'limit' for the items being shown. Else if the number of gigs, for example, goes up to 1000, all the 1000 will get shown.
Showing only a handful of items at each go also requires you to place the paginatator (the 'next' 'prev' buttons).
You can find more info about it at
http://www.couchcms.com/docs/concepts/l ... pages.html
http://www.couchcms.com/docs/concepts/pagination.html

Let me know if need any help.
Hi,

That's great; just what I needed! Thanks.

I thought it would be something simple, but it's so HARD to find it!

Thanks for your great support yet again!

G.
5 posts Page 1 of 1

Who is online

In total there are 12 users online :: 0 registered, 0 hidden and 12 guests
(based on users active over the past 5 minutes)

Users browsing this forum: No registered users and 12 guests