1. 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

Discussion in 'XenForo Development Discussions' started by Myke623, Oct 22, 2014.

  1. Myke623

    Myke623 Active Member

    I have some template code as follows:
    {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:
    {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?
  2. Chris D

    Chris D XenForo Developer Staff Member

    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}}
  3. Myke623

    Myke623 Active Member

    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.
  4. Myke623

    Myke623 Active Member

    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:
    return preg_replace('/>/', '►', $content);
    Chris D likes this.

Share This Page