Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2021-02-08 18:37:31

nobi-wan
Member
Registered: 2021-02-05
Posts: 23

Attach image class using image category?

Hello!

I want to attach classes to images, for use like the below, but you can’t do that. Why doesn’t this work? Be kind, I know it might be a daft question, but didn’t someone say there are no daft questions? Is there another way? Thanks!

<txp:images>
    <txp:image class='<txp:category type="image"/>'/>
</txp:images>

Offline

#2 2021-02-08 18:53:09

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

Re: Attach image class using image category?

Not a daft question at all! You’re very very close:

<txp:images>
    <txp:image class='<txp:image_info type="category" />' />
</txp:images>

The reason that works is because inside the <txp:images> tag you are in image context and then you can freely use the image_info tag to extract whatever you want from the current image being displayed.

<txp:category> however has its context tied to the URL so if you were displaying all images from a particular category like this: example.com/category/image/paris then <txp:category type="image" /> would return “paris”.


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 2021-02-08 20:03:48

nobi-wan
Member
Registered: 2021-02-05
Posts: 23

Re: Attach image class using image category?

Bloke — Thank you good sir. I remember well you helping me greatly ten years ago with a previous project with similarly wacky needs. 👏🏻👑

Offline

Board footer

Powered by FluxBB