Holoweb Posted July 24, 2023 Share Posted July 24, 2023 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 More sharing options...
AddWeb Solution Posted July 25, 2023 Share Posted July 25, 2023 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 More sharing options...
AddWeb Solution Posted July 25, 2023 Share Posted July 25, 2023 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 More sharing options...
Holoweb Posted July 25, 2023 Author Share Posted July 25, 2023 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 More sharing options...
endriu107 Posted July 25, 2023 Share Posted July 25, 2023 Try like that: {$product.description_short|truncate:150:'...' nofilter} Link to comment Share on other sites More sharing options...
AddWeb Solution Posted July 26, 2023 Share Posted July 26, 2023 Also Try if this helps {$product.description_short|substr:0:150}... substr modifier to extract the first 150 characters from the description_short variable, and then we append the ellipsis (...) to indicate that the description has been truncated. Thanks! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now