Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
The trouble with article_image as an element background
I want to do background-size:cover
like all the cool kids, and I’m using this hack to get it going:
<div id="header-img" style="background-image:url(<txp:image_url id='<txp:custom_field name="article_image" />' />)"></div>
Works great, until I get to an article where the article image is /images/center.jpg
… in other words, a relative URL instead of a reference to an image in the TXP database. I guess I’m looking for a snippet of PHP that checks to see if the first character in the field is a slash?
Yes, I have tried turning it off and on.
Offline
Re: The trouble with article_image as an element background
alesh wrote #283161:
Works great, until I get to an article where the article image is
/images/center.jpg
… in other words, a relative URL instead of a reference to an image in the TXP database.
Shouldn’t article_image generate something like http://[your site]/images/3.jpg ?
Offline
#3 2014-08-23 11:26:00
- uli
- Moderator
- From: Cologne
- Registered: 2006-08-15
- Posts: 4,304
Re: The trouble with article_image as an element background
You can use the “pattern” mode of if_custom_field
to check the content of the article image field like it were a normal custom field and then compose the image url accordingly:
<txp:if_custom_field name="article_image" match="pattern" value="^/.*">
PATH
<txp:else />
NUMBER
</txp:if_custom_field>
In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links
Offline
Re: The trouble with article_image as an element background
Whoa, while I wasn’t looking they added regular expressions to Textpattern.AWESOME
Yes, I have tried turning it off and on.
Offline
Re: The trouble with article_image as an element background
Ok, so when was this added and how many tags does it affect… regex is awesome
Offline
#6 2014-08-25 17:23:37
- uli
- Moderator
- From: Cologne
- Registered: 2006-08-15
- Posts: 4,304
Re: The trouble with article_image as an element background
Yeah, it’s great to have in TXP, and no rocket science.
It’s little known probably cause it’s not sampled in the docs. I just took the chance and tried it out.
An if_variable regexer, that’s where fishes start flying :)
In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links
Offline
Re: The trouble with article_image as an element background
uli wrote #283225:
It’s little known probably cause it’s not sampled in the docs. I just took the chance and tried it out.
I downloaded a pdf version on June 30th, 2011, and the option match="pattern"
is already mentioned.
An if_variable regexer, that’s where fishes start flying :)
Offline