Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
[textile] !imageurl! hard-codes URL in MySQL
This is an interesting one, and by “interesting” I mean “great, now I have to go back in and edit a bajillion articles.” :)
<txp:site_url /> was not working inside the Content > Write Body field on localhost, so I resorted to using Textile’s !imageurl!
syntax, which did work. Unfortunately, TXP is hardcoding the image path that !imageurl!
generates inside the MySQL > textpattern > Body_html table. This means that when the DB is exported, all the image paths are wrong (mine are hardcoded to localhost root — not really useful on my live site).
If I open each article to edit, change nothing, and just re-publish it, the path fixes itself to point back to the correct base URL.
Is this on the developers’ radar? Seems like it could be an easy fix. In the meantime, I guess I’ll be reading up on how to find & replace in MySQL. :(
Last edited by jaredigital (2009-08-04 04:19:21)
Offline
Re: [textile] !imageurl! hard-codes URL in MySQL
Textile uses the current site’s URL to build the img src
attribute at the very moment it generates HTML from Textile if you use relative URLs for !imgurl!
, i.e. URLs without a protocol and host part. This is done whenever an article is saved. If you move the site and resave articles later on, a new img src
will result.
This is intended behaviour. There are other ways if you need more portability, e.g. <txp:image />
is a tag which renders the img
element dynamically upon each request.
Offline
Re: [textile] !imageurl! hard-codes URL in MySQL
Ah, I see. Any ideas on how to get <txp:site_url /> to work inside an article on localhost?
Offline
Re: [textile] !imageurl! hard-codes URL in MySQL
In what way is it not working? It works as expected for me.
Code is topiary
Offline
Re: [textile] !imageurl! hard-codes URL in MySQL
When I use <txp:site_url /> in the Write > Body field, all it does is output the image path in text. But the tag works fine on my web host. It’s just localhost that does not do it right. I’ve tested on 2 different MAMP installations on 2 different computers with the same results. Maybe it’s a MAMP thing?
Offline
Re: [textile] !imageurl! hard-codes URL in MySQL
jaredigital wrote:
When I use <txp:site_url /> in the Write > Body field, all it does is output the image path in text. But the tag works fine on my web host. It’s just localhost that does not do it right. I’ve tested on 2 different MAMP installations on 2 different computers with the same results. Maybe it’s a MAMP thing?
Might be; I wouldn’t know as I don’t use MAMP. What output are you getting? At any rate, is there any reason not to use <txp:image />
as wet suggests?
Code is topiary
Offline
Re: [textile] !imageurl! hard-codes URL in MySQL
On localhost, using <txp:site_url />
outputs text. So where there should be an image is instead a line of text, like http://localhost:8888/jaredigital/image.png
. when I use the tag in the same exact context on my live site, online, the image displays as expected.
I can’t use <txp:image />
because these particular images have not been uploaded via the TXP image tab so there is no ID to reference.
It’s not a huge deal, as I was able to figure out how to search & replace the incorrect URL on all those images in MySQL. I just think it’s weird that within an environment like TXP, where pretty much everything can (and should) be relative to a moveable root, !imageurl!
is not. Threw me for a loop. :o
Offline
Re: [textile] !imageurl! hard-codes URL in MySQL
jaredigital wrote:
On localhost, using
<txp:site_url />
outputs text.
As it should — that’s all the tag does.
So where there should be an image is instead a line of text, like
http://localhost:8888/jaredigital/image.png
. when I use the tag in the same exact context on my live site, online, the image displays as expected.
What is the context? There’s no way that <txp:site_url />
can produce an image by itself. Surely you are using something like <img src="<txp:site_url />image.png" />
?
I just think it’s weird that within an environment like TXP, where pretty much everything can (and should) be relative to a moveable root,
!imageurl!
is not.
I agree, it’s a bit weird, and not what I would have expected either.
Code is topiary
Offline
Re: [textile] !imageurl! hard-codes URL in MySQL
What is the context? There’s no way that <txp:site_url /> can produce an image by itself. Surely you are using something like <img src=”<txp:site_url />image.png” />?
Sorry, I got a little mixed up there. :) Yes, I am trying to use <img src="<txp:site_url />image.png" />
in an article body on localhost. That outputs a broken image. When I view source, I see this: <p><img src="http://localhost:8888/jaredigital/image.png” /></p>
Characters at the end are getting converted to unicode (it’s unicode, right?), which breaks the image. Very odd.
Last edited by jaredigital (2009-08-04 15:33:11)
Offline
#10 2009-08-04 15:42:47
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: [textile] !imageurl! hard-codes URL in MySQL
Could be Textile. Try
==<img src="<txp:site_url />image.png" />==
or
notextile. <img src="<txp:site_url />image.png" />
Offline
Re: [textile] !imageurl! hard-codes URL in MySQL
Thanks, Els!
Both of those work, though notextile.
also removes the <p>
tags from around the image, which is great. Awesome! I have found my solution! :)
Offline