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

{xen:helper wordTrim function breaks the smilies on custom message

wang

Well-known member
#1
I working on an add on and I have come across this issue that I cannot seem to find the solution. I am trying to display smilies on a custom page and that works. But when I try to show an excerpt of the message, then all smilies break into html code. They are not parsed correctly anymore.

This is the code that I am using to parse the smilies.

HTML:
{xen:raw $message.messageParsed}
This works fine. But when I add the {xen:helper wordTrim function to show only 100 characters, it is not working anymore.

This is how I am adding it.

HTML:
{xen:string nl2br, {xen:helper wordTrim, {xen:raw $message.messageParsed}, 100}}
I have been trying to find a solutions for hours now, but no luck. Some help would be much appreciated.
 

Chris D

XenForo developer
Staff member
#2
It's the order of the operations here that's the problem. Something like this would work:
Code:
{xen:raw {xen:string nl2br, {xen:helper wordTrim, {$message.messageParsed}, 100}}
 

wang

Well-known member
#3
It's the order of the operations here that's the problem. Something like this would work:
Code:
{xen:raw {xen:string nl2br, {xen:helper wordTrim, {$message.messageParsed}, 100}}
Thank you very much for your help sir. I truly do appreciate it :) It was very frustrating to me that I could not find a solution.

I get a template syntax error when I tried that. I tried a few other combination and it was the same result.
 

wang

Well-known member
#4
I found a way to fix this. I removed the wordTrim function from the template, and I used the XenForo_Helper_String::wholeWordTrim() function to the my viewer php file instead, like this.

PHP:
$message.messageParsed = $parser>render(XenForo_Helper_String::wholeWordTrim($message.messageParsed ,100));
I hope that this can help other users too, who will run into the same glitch I did.

I want to thank again @Chris D for his help. Thank you sir :)