All times are UTC + 5:30 hours




Post new topic Reply to topic  [ 5 posts ] 
  Print view

How to assign specific HTML class to last DIV in a list
Author Message
PostPosted: Fri Jul 15, 2011 3:39 pm 
Registered User
Offline

Joined: Sat Jul 09, 2011 12:49 am
Posts: 25
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:
<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.


Top
 Profile  
 

Re: Using 'IF' to specify HTML classes
PostPosted: Fri Jul 15, 2011 3:44 pm 
Moderator
Offline

Joined: Wed Dec 01, 2010 5:35 pm
Posts: 1387
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.


Top
 Profile  
 

Re: How to assign specific HTML class to last DIV in a list
PostPosted: Fri Jul 15, 2011 3:51 pm 
Registered User
Offline

Joined: Sat Jul 09, 2011 12:49 am
Posts: 25
Hi,

Here is the requested code:

Code:
<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.


Top
 Profile  
 

Re: How to assign specific HTML class to last DIV in a list
PostPosted: Fri Jul 15, 2011 4:20 pm 
Moderator
Offline

Joined: Wed Dec 01, 2010 5:35 pm
Posts: 1387
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:
<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.


Top
 Profile  
 

Re: How to assign specific HTML class to last DIV in a list
PostPosted: Fri Jul 15, 2011 4:24 pm 
Registered User
Offline

Joined: Sat Jul 09, 2011 12:49 am
Posts: 25
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.


Top
 Profile  
 

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC + 5:30 hours


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
© 2001-2010 SYS-Solutions All Rights Reserved