Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2012-12-14 16:46:01

milosevic
Member
From: Madrid, Spain
Registered: 2005-09-19
Posts: 390

Proposal of new image tag if_first_image inside txp:images

Some times I miss a tag like “txp:if_first_image” when using txp:images tag to retrieve a set of images.

Think in the typical product page in a e-commerce site for instance: You see a main photo and some thumbnails with other images about the product.
It will be nice to retrieve all images with a unique query, stiling the first different (bigger) than the others, with a code like this:

<txp:images auto_detect="article" wraptag="ul" break="">
<txp:if_first_image><li class="big"><txp:else/><li></txp:if_first_image>
<txp:image width="0" height="0"/>
</li>
</txp:images>

Nowaday we can do this stuff but need a complex code, something like this:

<txp:adi_calc name="counter" value="1"/>
<txp:images auto_detect="article" wraptag="ul" break="">
<txp:if_variable name="counter" value="1">
<li class="big"><txp:else/><li></txp:if_variable>
<txp:image width="0" height="0"/>
</li>
<txp:adi_calc name="counter" add="1"/>
</txp:images>

I suposse that “if_last_image” can be usseful for something too, but I really never needed it.


<txp:rocks/>

Offline

#2 2012-12-14 20:27:43

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: Proposal of new image tag if_first_image inside txp:images

+1. And if_last_image, if_first/last_link, if_first/last_file :)

Offline

#3 2012-12-14 20:39:21

GugUser
Member
From: Quito (Ecuador)
Registered: 2007-12-16
Posts: 1,473

Re: Proposal of new image tag if_first_image inside txp:images

For the first and the following images you can also work with the limit and offset attributes.

Offline

#4 2012-12-14 20:44:34

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

Re: Proposal of new image tag if_first_image inside txp:images

I’ve opened a issue report 340 for this.

Offline

#5 2012-12-14 20:57:53

kees-b
Member
From: middelburg, nl
Registered: 2004-03-03
Posts: 235
Website

Re: Proposal of new image tag if_first_image inside txp:images

Gocom wrote:

I’ve opened a issue report 340 for this.

… fist-file? fist-link? ;)

but the proposal is excellent!

Last edited by kees-b (2012-12-14 20:58:45)

Offline

#6 2012-12-14 21:15:22

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

Re: Proposal of new image tag if_first_image inside txp:images

Jorge, there’s actually no need for a plugin. A structure like this inside your images tag helps detecting at least the first image:

<txp:if_variable name="first-image" value="1">
   here goes code for image 2 and higher
<txp:else />
   code for first image goes here
<txp:variable name="first-image" value="1" />
</txp:if_variable>

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

Offline

#7 2012-12-14 22:29:28

milosevic
Member
From: Madrid, Spain
Registered: 2005-09-19
Posts: 390

Re: Proposal of new image tag if_first_image inside txp:images

Nice way uli, thanks! Anyway a if_first_image tag will be simpler for non programmers minds :-)


<txp:rocks/>

Offline

#8 2012-12-14 22:31:18

milosevic
Member
From: Madrid, Spain
Registered: 2005-09-19
Posts: 390

Re: Proposal of new image tag if_first_image inside txp:images

Gocom dijo:

I’ve opened a issue report 340 for this.

Thanks Gocom.


<txp:rocks/>

Offline

#9 2012-12-14 22:34:11

milosevic
Member
From: Madrid, Spain
Registered: 2005-09-19
Posts: 390

Re: Proposal of new image tag if_first_image inside txp:images

GugUser dijo:

For the first and the following images you can also work with the limit and offset attributes.

…if you know the limit. And the limit is not allways known.


<txp:rocks/>

Offline

#10 2012-12-14 22:49:59

GugUser
Member
From: Quito (Ecuador)
Registered: 2007-12-16
Posts: 1,473

Re: Proposal of new image tag if_first_image inside txp:images

Fine, in the future we will have the new tags. But now, the limit for the first is one (1).

Offline

#11 2012-12-14 22:53:39

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

Re: Proposal of new image tag if_first_image inside txp:images

r5063, r5064 and 5065 together introduce these missing list conditionals, adding total of 6 new tags:

  • txp:if_first_image
  • txp:if_last_image
  • txp:if_first_link
  • txp:if_last_link
  • txp:if_first_file
  • txp:if_first_file

Each of these tags can be used in their respective list contexts similarly to the existing _last/_first tags.

Images:

<txp:images wraptag="ul" break="li">
	<txp:if_first_image>first</txp:if_first_image>
	<txp:if_last_image>last</txp:if_last_image>
</txp:images>

Links:

<txp:linklist wraptag="ul" break="li">
	<txp:if_first_link>first</txp:if_first_link>
	<txp:if_last_link>last</txp:if_last_link>
</txp:linklist>

Files:

<txp:file_download_list wraptag="ul" break="li">
	<txp:if_first_file>first</txp:if_first_file>
	<txp:if_last_file>last</txp:if_last_file>
</txp:file_download_list>

kees-b wrote:

… fist-file? fist-link? ;)

You can’t believe how common typo that is for me. Daily pain.

Offline

#12 2012-12-14 23:05:37

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,448
Website GitHub

Re: Proposal of new image tag if_first_image inside txp:images

Gocom wrote:

You can’t believe how common typo that is for me. Daily pain.

Snap.

New tags noted

Last edited by Bloke (2012-12-14 23:05:54)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

Board footer

Powered by FluxBB