Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Use a global to replace a certain text code to an image?

Quote Reply
Use a global to replace a certain text code to an image?
I'm not sure how to go about doing this.

I want it so that when someone enters the following text :b: into the description of their link, it should change it to an image that I have stored on my server

In a modern day forum, I would simply use :b: as a censored word and translate the censored word to the <img src= bla bla bla.gif> html code.

Is there maybe a simple way of doing that, maybe as a template golbal or something like that?

So that when somone types :b: it gets translated onto the detailed.html page as the img src html code tag of my choice.

Thanks,

P.S. I thought it might be as simple as adding a template global named :b: and the contents of the global be the actual html img src tag, but that didn't do anything for me.
Quote Reply
Re: [Westin] Use a global to replace a certain text code to an image? In reply to
Hi,

Well, should be as simple as:

replace_html_with_image
Code:
sub {
my $replace_with = q|<img src="whatever you want" />|;
my $tmp = $_[0];
$tmp =~ s/\Q:b:/$replace_with/sig;
return $tmp;
}

,...then call with:

<%replace_html_with_image($Description)%>

This would replace :b: with the value in $replace_with.

Hope that helps.

Cheers

Andy (mod)
andy@ultranerds.co.uk


IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates
Quote Reply
Re: [Andy] Use a global to replace a certain text code to an image? In reply to
Thanks Andy, I'll try that.

What is it that I need to change in this coding since I've got a total of 5 different images that will be needed to be called using simple tags :b: :u: :f: :w: :r:

I understand replacing the :b: in the example you gave and of course the img src, but what about the name of the global and any other coding in the global? Or would I call them all the same name and only change the img src and the :b: tags?
Quote Reply
Re: [Westin] Use a global to replace a certain text code to an image? In reply to
Okay, Im getting a similar error as before: Error: Variable 'replace_html_with_image' is not a code reference

Global Name: replace_html_with_image
Code:
sub {
my $replace_with = q|<img src="http://www.mydomain.com/images/black_mana.gif" />|;
my $tmp = $_[0];
$tmp =~ s/\Q:b:/$replace_with/sig;
return $tmp;
}

On Detailed.html template:
Code:
<%replace_html_with_image($Description)%>

Quote Reply
Re: [Westin] Use a global to replace a certain text code to an image? In reply to
Mmm, looks ok to me (no extra spaces anywhere)

Not sure without having a look.

Cheers

Andy (mod)
andy@ultranerds.co.uk


IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates