XF 2.0 Truncate text

Cupara

Well-known member
On my portal it displays the full content of threads, I am wanting to truncate the text to only show so many characters based on an option I added, do I do that via PHP or can that be done in my template? Either way, is the same method from XF1 viable or is there another way I have to do it in XF2?
 
Found what I was looking for, just used snippet as I discovered by digging through files.
 
Sure.

Using a template just do this:
PHP:
{{ snippet($post.messge, $limitCharacters, {'stripQuote': true}) }}

If your using BBCode then this is how you do it within the BBCode tags:
PHP:
                        <blockquote class="message-body">
                            {{ bb_code(snippet($post.message, $xf.options.xenPortalTruncate), 'post', $post.User, {
                                'attachments': $post.attach_count ? $post.Attachments : [],
                                'viewAttachments': $thread.canViewAttachments()
                            }) }}
                           
                        </blockquote>

Notice you take away the {{ }} and don't have to use stripQuote. Just replace $post.message or whatever variable you're using for the message with:
PHP:
snippet($message, $characterLimit)
 
Last edited:
Back
Top Bottom