• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Replacing content returned by xen:raw

Myke623

Active member
#1
I have some template code as follows:
Code:
{xen:raw $myContent}
which mainly contains text and some smiley code, hence the need for the xen:raw tag.

However, within this content I'd like to replace all occurrences of the greater-than symbol (>) with the unicode geometric shape ► (►).

I've tried to nest my own helper in there:
Code:
{xen:raw {xen:helper myhelper, $myContent} }
but that produces a template error on save (Invalid variable reference).

One work-around would be to create a new smiley image to replicate the right-pointing pointer shape, but I feel there's a much simpler solution.

Anyone know of a way to achieve this?
 

Chris D

XenForo developer
Staff member
#2
Your content in the raw block basically contains HTML so replacing > is going to cause you problems.

Unless the characters you are replacing are encoded in which case you could do a replacement on >

Anyway, you can do what you tried already with the helper but it would have to be the other way around.

{xen:helper yourhelper, {xen:raw $var}}
 

Myke623

Active member
#3
Is there a way I can encode the > prior to it saving (e.g. via a form)?

If not, then I guess I'll have to use a different character other than > to replace.
 

Myke623

Active member
#4
Is there a way I can encode the > prior to it saving (e.g. via a form)?
Actually, never mind that.

Since the helper is running first (i.e., before the xen:raw outputs html), there's no harm in replacing the >'s since they're already encoded.

My helper code is simply thus:
Code:
return preg_replace('/>/', '►', $content);