Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
#1 2018-12-04 10:38:45
- Gallex
- Member
- Registered: 2006-10-08
- Posts: 1,303
tag <txp:images />
my form:
<txp:images category='toetajad' wraptag="div" break="" class="partnerid" sort="date desc" />
outputs:
<div class="partnerid">
<a href="http://tartulumepark.ee/category/image/toetajad/?p=8"><img src="http://tartulumepark.ee/images/8t.jpg" alt="" /></a>
<a href="http://tartulumepark.ee/category/image/toetajad/?p=10"><img src="http://tartulumepark.ee/images/10t.jpg" alt="" /></a>
....
</div>
but i would like (no thumbnails, no wrapped with a):
<div class="partnerid">
<img src="http://tartulumepark.ee/images/8.jpg" alt="" />
<img src="http://tartulumepark.ee/images/10.jpg" alt="" />
....
</div>
Offline
Re: tag <txp:images />
Then use it as a container so you can design your own output instead of relying on the default. e.g.:
<txp:images category="toetajad" wraptag="div" break="" class="partnerid" sort="date desc">
<txp:image width="0" height="0" />
</txp:images>
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
#3 2018-12-04 13:09:38
- Gallex
- Member
- Registered: 2006-10-08
- Posts: 1,303
Re: tag <txp:images />
Bloke wrote #315479:
Then use it as a container so you can design your own output instead of relying on the default. e.g.:
<txp:images category="toetajad" wraptag="div" break="" class="partnerid" sort="date desc">...
i solved this way:
<txp:images category='toetajad' wraptag="div" break="" sort="date desc">
<img src="<txp:image_url />" title='<txp:image_info type="caption" />' />
</txp:images>
Last edited by Gallex (2018-12-04 13:10:07)
Offline
#4 2018-12-05 10:17:01
- Gallex
- Member
- Registered: 2006-10-08
- Posts: 1,303
Re: tag <txp:images />
developed further:
<txp:images category='toetajad' wraptag="div" break="" class="partnerid" sort="date desc">
<a href='<txp:image_info type="alt" />' target="new"><img src="<txp:image_url />" title='<txp:image_info type="caption" />' /></a>
</txp:images>
outputs:
<a href='https://www.google.com/' target="new"><img src="https://tartulumepark.ee/images/11.jpg" title='' /></a>
now code uses image’s alternate text/input as an url for an anchor, and all works fine. problem occurs then image hasn’t url inserted into alt input, then it outputs:
<a href='' target="new"><img src="https://tartulumepark.ee/images/11.jpg" title='' /></a>
is it somehow possible to do like this:
<txp:images category='toetajad' wraptag="div" break="" class="partnerid" sort="date desc">
if image has alt text then do this:
<a href='<txp:image_info type="alt" />' target="new"><img src="<txp:image_url />" title='<txp:image_info type="caption" />' /></a>
if not, this:
<img src="<txp:image_url />" title='<txp:image_info type="caption" />' />
</txp:images>
Offline
Re: tag <txp:images />
Sure. Are you running 4.7.1? If so you can use the evaluate tag to test
the output of the image_info tag:
<txp:images category="toetajad" wraptag="div" break="" class="partnerid" sort="date desc">
<txp:variable name="img_tag" escape="trim">
<img src="<txp:image_url />" title='<txp:image_info type="caption" />' />
</txp:variable>
<txp:evaluate test="image_info">
<a href='<txp:image_info type="alt" />' target="new"><txp:variable name="img_tag" /></a>
<txp:else />
<txp:variable name="img_tag" />
</txp:evaluate>
</txp:images>
Note that I stored the <img>
tag itself in a variable outside the <txp:evaluate>
test. This is because you’re using <txp:image_info>
twice – once for alt and once for caption. If the caption tag was left inside the container of the <txp:evaluate>
tag, it would look at both tags to see if either contained anything and only return false if BOTH were empty, which is not what you want.
The side benefit here of storing the image tag in a variable is that you only have to edit it once if you wish to change it in future, instead of in both branches of the ‘else’.
Hope that helps.
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
#6 2018-12-05 12:55:02
- Gallex
- Member
- Registered: 2006-10-08
- Posts: 1,303
Re: tag <txp:images />
wow!!
and if i drop caption, the code would look:
<txp:images category="toetajad" wraptag="div" break="" class="partnerid" sort="date desc">
<txp:evaluate test="image_info">
<a href='<txp:image_info type="alt" />' target="new"><img src="<txp:image_url />" /></a>
<txp:else />
<img src="<txp:image_url />" />
</txp:evaluate>
</txp:images>
?
Offline
Re: tag <txp:images />
Yep.
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
#8 2018-12-05 13:34:02
- Gallex
- Member
- Registered: 2006-10-08
- Posts: 1,303
Re: tag <txp:images />
Offline
Re: tag <txp:images />
You’re welcome. It’s mainly the genius of etc (Oleg) to thank for this fabulous tag flexibility we have now.
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: tag <txp:images />
Bloke wrote #315491:
It’s mainly the genius of etc (Oleg) to thank for this fabulous tag flexibility we have now.
The genius is our txp community, since I have borrowed the idea from Adi (who has borrowed it from someone else). Pushing flexibility a bit farther:
<txp:images category="toetajad" wraptag="div" break="" class="partnerid" sort="date desc">
<txp:evaluate wraptag='<txp:evaluate><a href=''<txp:image_info type="alt" />'' target="new"><+></a></txp:evaluate>'>
<img src="<txp:image_url />" title='<txp:image_info type="caption" />' />
</txp:evaluate>
</txp:images>
Offline
#11 2018-12-06 08:56:22
- Gallex
- Member
- Registered: 2006-10-08
- Posts: 1,303
Re: tag <txp:images />
etc wrote #315492:
<txp:images category="toetajad" wraptag="div" break="" class="partnerid" sort="date desc">...
oleg, could you comment your solution a bit? it’s hard to understand for me. ;) <+>
– what is this?
Last edited by Gallex (2018-12-06 08:57:01)
Offline
Re: tag <txp:images />
Gallex wrote #315496:
<+>
– what is this?
It’s a placeholder in wraptag
attribute that will be replaced by the tag output. For example,
<txp:site_name wraptag="<h1>The name of my site is <i><+></i></h1>" />
will return
<h1>The name of my site is <i>Your Site Name</i></h1>
In your case wraptag
will be not empty only if <txp:image_info type="alt" />
is set, in which case the image will be wrapped in <a ...></a>
. And if it doesn’t need a title, you can simplify the block even more:
<txp:images category="toetajad" wraptag="div" break="" class="partnerid" sort="date desc">
<txp:image wraptag='<txp:evaluate><a href=''<txp:image_info type="alt" />'' target="new"><+></a></txp:evaluate>' />
</txp:images>
Offline
Pages: 1