Problems, need help? Have a tip or advice? Post it here.
3 posts Page 1 of 1
Hi.

Maybe the subject line says it clearly enough, but ...

Is there a way to check if an <excerpt> is NOT truncated and then add a bit of html to the end of the item? (I.e., the item being excerpted is shorter than the excerpt limit.)

For example, is there a variable that exists (or that can be set) that I can use with a <cms:if>?
No such variable exists out of the box but you may create your own by using a bit of PHP.
As an example, try the following -
Code: Select all
<cms:capture into='my_buffer'>
    <cms:excerpt count='200'>
        Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud
    </cms:excerpt>
</cms:capture>

<cms:php>
    global $CTX;
    $is_truncated = ( substr(trim($CTX->get('my_buffer')), -8)=='&hellip;') ?  1 : 0;
    $CTX->set( is_truncated, $is_truncated, 'global' );
</cms:php>
   
<cms:show my_buffer />
<cms:if "<cms:not is_truncated />" >
    [NOT TRUNCATED]
</cms:if>

In the code above, we first buffer the excerpted content and then use PHP to check if a '&hellip;' character is found at the very end of it (<cms:excerpt> would do this if the string was truncated). A variable named 'is_truncated' is set showing the result which can be used later in your code.

Hope this helps.
Brilliant. Thank you, KK.
3 posts Page 1 of 1

Who is online

In total there are 3 users online :: 0 registered, 0 hidden and 3 guests
(based on users active over the past 5 minutes)

Users browsing this forum: No registered users and 3 guests