Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2013-10-03 09:29:23

gaekwad
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 4,137
GitHub

Hack <txp:article_image /> to just output the URL

Hi, everyone.
I’d like to use article_image to just output the URL of the image associated with the article, without having it tack on the img wrapper as it is designed to do. As it stands, an article image of http://example.com/foo.png will be outputted by article_image as <img src="http://example.com/foo.png" alt="" />. Because I’m bodging the image into a div background I don’t need the wrapper.

My plan is to either use rah_replace to cut out the bits I don’t need, or etc_query to scoop what I need from the database directly. Is there another way I haven’t thought of that is regarded as ‘better’?

Thank you in advance.

Offline

#2 2013-10-03 09:51:05

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

Re: Hack <txp:article_image /> to just output the URL

Try this:

<txp:images break=""><txp:image_url /></txp:images>

(code note tested)

Offline

#3 2013-10-03 09:55:07

gaekwad
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 4,137
GitHub

Re: Hack <txp:article_image /> to just output the URL

Hi Rabah, thank you for your reply. This is the code I used:

<txp:if_article_image><!-- image test <txp:images break=""><txp:image_url /></txp:images> --></txp:if_article_image>

…and this is the output in the browser inspector:

<!-- image test <img src="http://example.com/foo.png" alt="" class="images" /> -->

So, alas, it didn’t work; regardless, I am grateful for your suggestion and reply.

Last edited by gaekwad (2013-10-03 09:55:26)

Offline

#4 2013-10-03 10:03:53

springworks
Member
Registered: 2005-01-06
Posts: 172
Website

Re: Hack <txp:article_image /> to just output the URL

Strange, I’ve just tested your code in an article form context and it works for me.

Offline

#5 2013-10-03 10:04:05

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

Re: Hack <txp:article_image /> to just output the URL

gaekwad wrote:

So, alas, it didn’t work; regardless, I am grateful for your suggestion and reply.

Well, it does work. image_url gives you an URL, nothing more, nothing less.

Offline

#6 2013-10-03 10:05:58

gaekwad
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 4,137
GitHub

Re: Hack <txp:article_image /> to just output the URL

Hi Steve and Jukka.
Thanks for your replies. I will re-test.

Offline

#7 2013-10-03 10:11:31

gaekwad
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 4,137
GitHub

Re: Hack <txp:article_image /> to just output the URL

OK, forgive my stupidity: how does images and image_url work in an article form context? I should’ve said I’m using article_image in an article form and the image are hosted elsewhere, i.e., not uploaded in the images panel. Let’s say I am running http://example.org and the article image is on http://example.com.

My understanding is that images works with uploaded images, and that image_url gives a URL for a chosen image ID. The article image in this case is not an uploaded image, so has no reference on the images tab.

The URL does exist in the database and article_image also wraps it with the img tag correctly; I’m scratching my head as to where the correlation with the images tab and article images exists.

Again, please forgive my stupidity. I appreciate your guidance.

Last edited by gaekwad (2013-10-03 10:13:59)

Offline

#8 2013-10-03 10:16:01

gaekwad
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 4,137
GitHub

Re: Hack <txp:article_image /> to just output the URL

Oh, OK, I think I found it in the wiki:

By default, the tag is context-sensitive, which means that in the absence of any filter attributes (id, name, category, author, realname, extension, thumbnail), it will return image IDs from the first of: the currently viewed article’s article_image field; images matching the global category context; images matching the global author context; all images.

Mea culpa.

Offline

#9 2013-10-03 10:19:40

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

Re: Hack <txp:article_image /> to just output the URL

gaekwad wrote:

My understanding is that images works with uploaded images

Yes. Can’t do what you are doing.

Offline

#10 2013-10-03 10:26:40

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

Re: Hack <txp:article_image /> to just output the URL

Hi

If images are elsewhere then put the url image in a custom field and use it as you want!

Offline

#11 2013-10-03 10:38:54

gaekwad
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 4,137
GitHub

Re: Hack <txp:article_image /> to just output the URL

Gocom wrote:

Yes. Can’t do what you are doing.

The wiki says:

By default, the tag is context-sensitive, which means that in the absence of any filter attributes […], it will return image IDs from the first of: the currently viewed article’s article_image field; […]

As I understand it, the article_image doesn’t have an ID as such; should that then output the raw URL?

I’ve double checked my code to make sure it’s accurate and follows Rabah’s suggestion. This is what I have in my admin-side markup (the image is the real one, rather than an RFC-reserved one:

<txp:if_article_image><!-- rabah's individual article image test <txp:images break=""><txp:image_url /></txp:images> --></txp:if_article_image>

This is what I have as the article image:

http://ad.linksynergy.com/fs-bin/show?id=j6vpFg*1lv0&bids=305847.10000753&type=3&subid=0&u1=prag

…and this is what comes out in the browser inspector:

<!-- rabah's individual article image test <img src="http://ad.linksynergy.com/fs-bin/show?id=j6vpFg*1lv0&amp;bids=305847.10000753&amp;type=3&amp;subid=0&amp;u1=prag" alt="" class="images" /> -->

...here's the relevant chunk of tag trace:
	<txp:if_article_image>
		[<txp:if_article_image>: true]
		<txp:images break="">
		</txp:images>
	</txp:if_article_image>

There’s no reference to the commented out section of the admin-side markup, but it appears to check out as expected. As an aside, there doesn’t appear to be an escape attribute for image_url, either, which breaks the ampersands in my article image; not a criticism, just an observation.

Last edited by gaekwad (2013-10-03 10:54:10)

Offline

#12 2013-10-03 10:39:58

gaekwad
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 4,137
GitHub

Re: Hack <txp:article_image /> to just output the URL

Dragondz wrote:

If images are elsewhere then put the url image in a custom field and use it as you want!

Your idea is great – unfortunately, I’m using all ten custom fields already!

Offline

Board footer

Powered by FluxBB