noesac Posted July 3, 2010 Share Posted July 3, 2010 I have been modifying the truncate variable in homefeatured.tpl: {$product.name|truncate:35:'...'|escape:'htmlall':'UTF-8'} It works most of the time, but occasionally it's not enough: http://i48.tinypic.com/rap3lc.jpgI think that truncating based on characters and not words might help with this issue, so I'm interested in experimenting. EXAMPLE: FULL TITLE: "LEVIS JEANS LARGE SIZE BLUE COLOUR"CURRENTLY TRUNCATED LIKE: "LEVIS JEANS LARGE..."WHAT I WOULD LIKE TO EXPERIMENT WITH: "LEVIS JEANS LA..."Any ideas how I do this? Link to comment Share on other sites More sharing options...
eltitos Posted July 3, 2010 Share Posted July 3, 2010 you changed the truncate of the link's title not of the display text {$product.name|truncate:32:'...'|escape:'htmlall':'UTF-8'} Link to comment Share on other sites More sharing options...
noesac Posted July 3, 2010 Author Share Posted July 3, 2010 Hi there, yes it's the title that I want to truncate (on the front page, Featured Products) Link to comment Share on other sites More sharing options...
eltitos Posted July 3, 2010 Share Posted July 3, 2010 copy my previous code, it will be ok Link to comment Share on other sites More sharing options...
noesac Posted July 3, 2010 Author Share Posted July 3, 2010 thanks Eltitos, is it possible that you pasted the wrong code? that's the same one as mine Link to comment Share on other sites More sharing options...
eltitos Posted July 3, 2010 Share Posted July 3, 2010 no it's working, i just tried again.empty your browser cache. Link to comment Share on other sites More sharing options...
rocky Posted July 3, 2010 Share Posted July 3, 2010 You can use code like the following: <a href="{$product.link}" title="{$product.name|substr:0:32|escape:'htmlall':'UTF-8'|trim}{if $product.name|strlen > 32}...{/if}">{$product.name|substr:0:27|escape:'htmlall':'UTF-8'|trim}{if $product.name|strlen > 27}...{/if} This code will truncate the product title to 32 characters and link text to 27 characters, then trim any spaces, then add '...' on the end. Link to comment Share on other sites More sharing options...
noesac Posted July 3, 2010 Author Share Posted July 3, 2010 Thanks Rocky, is there an IF tag missing from the front of that?I got this error: Fatal error: Smarty error: [in /home/testsite/public_html/modules/homefeatured/homefeatured.tpl line 25]: syntax error: unclosed tag \{foreach} (opened line 24). (Smarty_Compiler.class.php, line 317) in /home/testsite/public_html/tools/smarty/Smarty.class.php on line 1095 Link to comment Share on other sites More sharing options...
rocky Posted July 3, 2010 Share Posted July 3, 2010 The PrestaShop forums deleted part of my code again. :roll: I've fixed my code above. Link to comment Share on other sites More sharing options...
noesac Posted July 3, 2010 Author Share Posted July 3, 2010 That did the trick, thanks again Rocky! To everyone else - I didn't know how this would look...but I just tested it with 20 products on my front page and it looks fine (I was worried truncating words in half might look unusual but nothing to worry about) Link to comment Share on other sites More sharing options...
noesac Posted July 4, 2010 Author Share Posted July 4, 2010 Hi Rocky I also want to apply this to the "in same category" slide bar (productscategory.tpl). I think I would need to change: getProductLink($categoryProduct.id_product, $categoryProduct.link_rewrite, $categoryProduct.category)}" title="{$categoryProduct.name|htmlspecialchars}"> {$categoryProduct.name|truncate:15:'...'|escape:'htmlall':'UTF-8'} To: getProductLink($categoryProduct.id_product, $categoryProduct.link_rewrite, $categoryProduct.category)}" title="{$categoryProduct.name|substr:0:32|escape:'htmlall':'UTF-8'|trim}"{if $categoryProduct.name|strlen > 32}...{/if}">{$categoryProduct.name|substr:0:22|escape:'htmlall':'UTF-8'|trim}{if $categoryProduct.name|strlen > 22}...{/if} Does that look right? Link to comment Share on other sites More sharing options...
rocky Posted July 4, 2010 Share Posted July 4, 2010 The forum deleted some of your code, but otherwise it looks fine. Link to comment Share on other sites More sharing options...
noesac Posted July 4, 2010 Author Share Posted July 4, 2010 Fantastic thanks Rocky, I just tried to edit the post in case anyone else wants to use it in the future. Hopefully that fixed it. Link to comment Share on other sites More sharing options...
rocky Posted July 4, 2010 Share Posted July 4, 2010 It didn't work. The trick is to rewrite <a href as <a href Link to comment Share on other sites More sharing options...
noesac Posted July 4, 2010 Author Share Posted July 4, 2010 I just updated the site and the code above:) I had an extra < in the code that I needed to delete. It should be working now hopefully:) Link to comment Share on other sites More sharing options...
noesac Posted July 4, 2010 Author Share Posted July 4, 2010 UPDATE: Oh it's working now, even a shift + refresh didn't seem to work. I had to navigate out of the page then back in again!This is really unusual, I went to clean up the code and add some comments and now it doesn't work! Any idea's what's gone wrong? Code remains as above Link to comment Share on other sites More sharing options...
Recommended Posts