Textpattern Forum

You are not logged in. Register | Login | Help

#1 2012-02-24 12:55:43

phuture303
Member
Registered: 2008-09-14
Posts: 118

Ignore image tages in body

Hey,

for a mobile version of a website I’d like to ignore the image tags which are placed in the body field. Are there any possibilities to do this?

Thanks in advance,
David

Offline

#2 2012-02-24 13:54:53

maniqui
Moderator
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 2,975
Website

Re: Ignore image tages in body

What about hiding them (display:none;) via CSS, by having a specific rule?

body.is_mobile div.article_body img {
   display:none;
}

Not sure if this will prevent downloading at all. That may depend on many different factors.

Alternatively, you may want to try smd_macro, to create a macro to embed images in the body field. Then, inside the macro, you use some kind of logic (via adi_mobile, for example), to decide if you want to output the image or not.


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#3 2012-02-24 14:03:38

phuture303
Member
Registered: 2008-09-14
Posts: 118

Re: Ignore image tages in body

Hi maniqui,

What about hiding them (display:none;) via CSS, by having a specific rule?

I tried that, but that won’t prevent loading the images.

The smd_macro idea seems to be a possibility, maybe i’ll give it a try (but then I’ll have to work on upm_image_popper which I use for embedding images :-)

Offline

#4 2012-02-24 14:07:21

Gocom
Developer
Registered: 2006-07-14
Posts: 4,471
Website

Re: Ignore image tages in body

maniqui wrote:

Not sure if this will prevent downloading at all. That may depend on many different factors.

Unless you use JavaScript, or CSS background property instead of HTML img tags, no it won’t.


Rah-plugins | What? I’m a little confused… again :-) <txp:is_god />

Offline

#5 2012-02-24 14:22:54

Gocom
Developer
Registered: 2006-07-14
Posts: 4,471
Website

Re: Ignore image tages in body

phuture303 wrote:

The smd_macro idea seems to be a possibility, maybe i’ll give it a try (but then I’ll have to work on upm_image_popper which I use for embedding images :-)

You could potentially use a form to output images. E.g.

<txp:output_form form="img">11</txp:output_form>

And then in the img form:

<txp:adi_if_mobile>
	<!--
		A mobile browser, do something else
	-->
<txp:else />
	<txp:images id='<txp:yield />'>
		<txp:thumbnail />
	</txp:images>
</txp:adi_if_mobile>

But that would require that you use the specific snippet to add every single image. No Textile or anything else allowed. Other, more robust, better solution might actually be some post-precessing. Like stripping the images with some regular expressions. I.e.

<txp:php>
	echo preg_replace('/<img[^>]+\>/i', '', body());
</txp:php>

Above would print out <txp:body /> with all <img/> instances removed. That could be then used with adi_mobile. E.g.

<txp:adi_if_mobile>
	<txp:php>
		echo preg_replace('/<img[^>]+\>/i', '', body());
	</txp:php>
<txp:else />
	<txp:body />
</txp:adi_if_mobile>

Last edited by Gocom (2012-02-24 14:27:53)


Rah-plugins | What? I’m a little confused… again :-) <txp:is_god />

Offline

#6 2012-02-24 14:33:35

phuture303
Member
Registered: 2008-09-14
Posts: 118

Re: Ignore image tages in body

<txp:php>
	echo preg_replace("/<img[^>]+\>/i", '', body());
</txp:php>

Gocom, made my day. That’s it – and so easy. Thank you very much!

Offline

Board footer

Powered by FluxBB