Jump to content

Truncate short description


Holoweb

Recommended Posts

PS 1.7.8.1

Hello! Im trying to trucate short description for products, but i can get it right. My code:

 

{block name='product_description_short'}
    <div id="product-description-short-{$product.id}" class="rte-content product-description">
        {if $product.description_short|strlen > 150}
            {$product.description_short|truncate:150:'...'|nofilter}
            <a href="your-link-for-read-more">Read More</a>
        {else}
            {$product.description_short|nofilter}
        {/if}
    </div>
{/block}

 

Can someone point me to the direction what im doing wrong?

Thank you!

Hugo

Link to comment
Share on other sites

Hi,

Instead of using `|strlen`, you should use `|count_characters`.

Make sure that the short description for products is actually longer than 150 characters for the truncation to take effect. If the short description is shorter than 150 characters, the condition will not be met, and the full description will be displayed without truncation.

Clear the cache and check If it works.

Thanks!

Link to comment
Share on other sites

If you've checked the above and still face issues, consider temporarily removing the if condition and else part to see if the truncation works without the condition. If it does, then there might be an issue with the condition itself.

Create a backup of your template files before making changes, so you can easily revert back if anything goes wrong.

Thanks!

Link to comment
Share on other sites

Thank you! unfortunately, this still causes issues. There is some syntax error im doing, whenerver i upload this, i get error while loading the shop on product pages. even this wont work:

                    {block name='product_description_short'}
                        <div id="product-description-short-{$product.id}"
                              class="rte-content product-description">{$product.description_short|truncate:150:'...'| nofilter}</div>
                    {/block}

                    {block name='product_description_short'}
                        <div id="product-description-short-{$product.id}"
                              class="rte-content product-description">{$product.description_short|truncate:150:'...'| nofilter}</div>
                    {/block}

Means that it soes not want to accept the truncation at all for some reason.

Thank you for yyour help! :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...