Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2013-05-04 08:52:32

brazhko
New Member
From: Stakhanov, Ukraine
Registered: 2010-12-30
Posts: 7
Website

How to detect the last image in the list?

Hi!

Help me, please.

<txp:images category="partners" wraptag="ul" break="" class="logo-list clearfix" sort="id">
            <txp:thumbnail wraptag="li" class="one-fifth" link="1" />
</txp:images>

but at last image i need class=“one-fifth column-last”.

<txp:if_last_image><txp:thumbnail wraptag="li" class="one-fifth column-last" link="1" /><txp:else /></txp:if_last_image>

dont work with error

Error tag: <txp:if_last_image> -> Textpattern Warning: tag does not exist in the processing of the form "partners" on the page "default"

In result I need

<ul class="logo-list clearfix">
    <li class="one-fifth"><a href="#"><img src="/images/content/logo_list_01.png" alt="" /></a></li>
    <li class="one-fifth"><a href="#"><img src="/images/content/logo_list_02.png" alt="" /></a></li>
    <li class="one-fifth"><a href="#"><img src="/images/content/logo_list_03.png" alt="" /></a></li>
    <li class="one-fifth"><a href="#"><img src="/images/content/logo_list_04.png" alt="" /></a></li>
    <li class="one-fifth column-last"><a href="#"><img src="/images/content/logo_list_05.png" alt="" /></a></li>
</ul>

Offline

#2 2013-05-04 14:16:24

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,315

Re: How to detect the last image in the list?

As you have to serve a CSS grid with a column-last class, we don’t need to care for four and less images, hence we can restrict ourselves to using only core tags.

Anywhere above your txp:images tag you need to define a variable value of 1 by putting <txp:variable name="img-num" value="1" /> there. Below in the page you add to that value: immediately in your thumbnail tag, namely inside the class attribute:

<txp:images category="partners" wraptag="ul" break="" class="logo-list clearfix" sort="id">
            <txp:thumbnail wraptag="li" class='one-fifth<txp:output_form name="img-counter" />' link="1" />
</txp:images>

I used an output_form tag here to keep the code readable. Note the single apostrophes around it.
Now create a form “img-counter”, type “misc”, and place the following code inside:

<txp:if_variable name="img-num" value="5"><txp:variable name="img-num" value="1" /> column-last</txp:if_variable>
<txp:if_variable name="img-num" value="4"><txp:variable name="img-num" value="5" /></txp:if_variable>
<txp:if_variable name="img-num" value="3"><txp:variable name="img-num" value="4" /></txp:if_variable>
<txp:if_variable name="img-num" value="2"><txp:variable name="img-num" value="3" /></txp:if_variable>
<txp:if_variable name="img-num" value="1"><txp:variable name="img-num" value="2" /></txp:if_variable>

This code is iterated over each time the txp:images tag is parsed and on each pass the value is raised, except for the first step/line. Note that the code advances from higher values to lower ones, but raises the value (if 4 –> 5). This way it prevents setting the value to the triggering “5” on each pass.

BTW: You’ll have to remove all the returns from the form’s code, they’d create lots of unnecessary white space in your HTML, they’re only good for reading here.


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#3 2013-05-04 14:23:59

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: How to detect the last image in the list?

Textpattern 4.5.0 and prior do not have a tag named if_last_image. The tag does exists, but only in the unstable 4.6-dev branch and nightlies. The tag was added in r5063.

Offline

#4 2013-05-04 14:42:12

Dragondz
Moderator
From: Algérie
Registered: 2005-06-12
Posts: 1,549
Website GitHub Twitter

Re: How to detect the last image in the list?

Hi

why not using a simple Css to achieve what you want because you dont need to add a class to the last item to style it like you want.

.one-fifth:last-child
{
     border-right: 0;
     margin-right: 0;
}

Offline

#5 2013-05-05 06:20:29

brazhko
New Member
From: Stakhanov, Ukraine
Registered: 2010-12-30
Posts: 7
Website

Re: How to detect the last image in the list?

Great, guys! Thanks! I used Dragondz’s css solution, it’s simple and effective.

Offline

Board footer

Powered by FluxBB