Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#1 2019-09-08 10:00:44
- mikulas
- Member
- From: Czech republic
- Registered: 2012-03-15
- Posts: 38
How to display images of range ids
Hi. Is there any possibility to display range of images using tag <txp:images />
and attribute id? I mean something like <txp:images id='<txp:custom_field name="image-ids" />' />
and in custom_filed is for example 235 - 296
.
I use jbx_multiple_image_upload plugin for uploading images, which can create a new category for uploaded images. This plugin uses Adobe Flash and its support is expected to end soon.
Last edited by mikulas (2019-09-08 10:03:27)
Offline
Re: How to display images of range ids
According to the docs for txp:images that’s not possible but you could do it with the help of rah_repeat and a tag-in-tag(-in-tag) solution.
rah_repeat does have a range
attribute. The standard setup uses a comma between the from and to ids but you can use the delimiter="-"
attribute to change that.
So this:
<txp:rah_repeat range='<txp:custom_field name="image-ids" />' delimiter="-" break=","><txp:rah_repeat_value /></txp:rah_repeat>
should give you 235, 236, 237 … 294,295,296
and you can use that as a value for txp:images
. Either you do a big tag-in-tag-in-tag construction like this:
<txp:images id='<txp:rah_repeat range=''<txp:custom_field name="image-ids" />'' delimiter="-" break=","><txp:rah_repeat_value /></txp:rah_repeat>'>
… your image code …
</txp:images>
(Note the double single quotes for range above).
Or you do it in two stages:
<txp:variable name="img_list" escape="trim">
<txp:rah_repeat range='<txp:custom_field name="image-ids" />' delimiter="-" break=","><txp:rah_repeat_value /></txp:rah_repeat>
</txp:variable>
<txp:images id='<txp:variable name="img_list" />'>
… your image code …
</txp:images>
Both should get you the results you want.
TXP Builders – finely-crafted code, design and txp
Offline
#3 2019-09-08 21:13:12
- mikulas
- Member
- From: Czech republic
- Registered: 2012-03-15
- Posts: 38
Re: How to display images of range ids
Great! It works. Thank you very much.
Only note:
The standard setup uses a comma between the from and to ids but you can use the
delimiter="-"
attribute to change that.
I must use a comma between the from and to ids otherwise the result is empty.
Offline
Re: How to display images of range ids
mikulas wrote #319242:
I must use a comma between the from and to ids otherwise the result is empty.
Hmm, maybe delimiter
only works in combination with the value
attribute and not with range
?
Glad you got it working!
TXP Builders – finely-crafted code, design and txp
Offline
Re: How to display images of range ids
Actually id
ranges is a useful feature. Worths incorporating into core?
Offline
Re: How to display images of range ids
etc wrote #319244:
Actually
id
ranges is a useful feature. Worths incorporating into core?
Yes. If only to help with large image galleries saving space in the (limited) fields. Can we permit multiples:
42, 25-31, 11, 61-64
to include 42, 25, 26, 27, 28, 29, 30, 31, 11, 61, 62, 63, 64 in that order.
Question remains what to do with duplicates. How do we handle them now, I can’t recall? e.g. if 41-43
was also in the above, is ID 42 included twice; once at the start and once in the 41, 42, 43 set?
My gut says permit duplicates, because you may be using the field as a gallery where the first image in the list is used as the ‘cover’ (main) image in the article list (via limit="1"
), but you may want to also include the same pic later (e.g. once you view the individual article) where you skip over the cover image via offset="1"
and show the remaining IDs in a gallery that may also include the same pic used as the cover. e.g. 42, 38-45
.
But if that seems too confusing then we can do_unique()
them if the order remains intact. I’m easy either way, as long as we retain b/w compatibility.
EDIT: anywhere else ID ranges make sense? <txp:article_custom>
or <txp:file_download_list>
for example? Anywhere they don’t make sense?
Last edited by Bloke (2019-09-09 11:19:49)
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
Re: How to display images of range ids
We could do it via a new <txp:list />
tag, though modifying existing id
attributes makes sense too. For bwc-sake, <txp:images id="40, 38-40" />
would act as <txp:images id="40,38,39" />
(unique ids), but <txp:list items="40, 38-40" />
would output 40,38,39,40
(by default).
Offline
Re: How to display images of range ids
Please test it in dev branch. Currently available in id
attribute of article_custom
, file_download_list
, images
and linklist
tags.
Offline
Re: How to display images of range ids
I like those ideas. I could have sworn we currently allow duplicates, but you’re right, they’re unique now – whether used in the tag implicitly, or if read from the Article Image field. That’s cool. I’m probably getting mixed up with smd_gallery which does permit duplicate ID behaviour, iirc.
A new tag to generate lists would be handy for tag-in-tag goodness. Is <txp:list>
too generic/confusing, given we have linklist, file_download_list, category_list and section_list tags? To me, <txp:list>
seems like it should have a type
attribute to determine which type of list you want from the above! But maybe that’s just me.
Alternatives:
<txp:range>
<txp:set>
(although that might be confused with get/set)<txp:series>
<txp:id_list>
(if it’s only going to be for generating numeric lists, and not (in future) for shortcuts like months of the year or days of the week, etc)- …
Shame that a new tag like you propose couldn’t give us the ability to process in-order lists and ranges with duplicates, from custom fields or the article_image field itself:
<txp:images id='<txp:list items=''<txp:custom_field name="article_image" />'' />' />
Slightly verbose! :) But as it stands, the list would still be made unique by the ‘id’ attribute.
Maybe allowing duplicates isn’t something we should worry about? Although I can see applications, if plugging the output of <txp:list>
into an id
attribute of any of our current tags is going to render its dupe-ability useless, there’s not much point incorporating the feature, is there? Aside from its use in plugins that do support this, I guess. Hmmmm.
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
Re: How to display images of range ids
Bloke wrote #319248:
A new tag to generate lists would be handy for tag-in-tag goodness. Is
<txp:list>
too generic/confusing, given we have linklist, file_download_list, category_list and section_list tags? To me,<txp:list>
seems like it should have atype
attribute to determine which type of list you want from the above! But maybe that’s just me.
I thought that could be a general-purpose tag, letting you (jointly with some <txp:item />
tag) split plain strings:
<txp:list items="I like dogs. I hate cats." separator="." break="br" wraptag="p">
<txp:item />!
</txp:list>
would output
<p>
I like dogs!
<br />
I hate cats!
</p>
Shame that a new tag like you propose couldn’t give us the ability to process in-order lists and ranges with duplicates, from custom fields or the article_image field itself.
We could, though laboriously:
<txp:list items=2, 1-3" separator="," range="-">
<txp:image id='<txp:item />' />
</txp:list>
Offline
Re: How to display images of range ids
Would it not be more logical if we just had what etc mentioned? ie <txp:images id="40, 38-40" />
. My only problem is that when I see 38-40
, I would expect the range to be inclusive. That is ids 38,39,40
. When kids are asked to count from 1-10 for example, they are expected to include 10.
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
Re: How to display images of range ids
colak wrote #319250:
My only problem is that when I see
38-40
, I would expect the range to be inclusive. That is ids38,39,40
.
That’s fine, 38-40
means 38,39,40
. But 40, 38-40
means 40,38,39
because the last 40
is removed as duplicate of the first one.
Offline