Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2014-08-22 21:45:34

alesh
Member
From: Miami, FL
Registered: 2005-04-13
Posts: 228
Website

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

#2 2014-08-22 23:26:01

michaelkpate
Moderator
From: Avon Park, FL
Registered: 2004-02-24
Posts: 1,379
Website GitHub Mastodon

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

#4 2014-08-25 14:06:56

alesh
Member
From: Miami, FL
Registered: 2005-04-13
Posts: 228
Website

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

#5 2014-08-25 16:35:11

mrdale
Member
From: Walla Walla
Registered: 2004-11-19
Posts: 2,215
Website

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

#7 2014-08-26 07:41:02

CeBe
Plugin Author
From: Caen - Fr
Registered: 2010-06-25
Posts: 345
Website

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 :)

cbe_if_variable ?

Offline

Board footer

Powered by FluxBB