Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls

Truncate product title in XC5
 
Reply
   X-Cart forums > X-Cart 5 > Modifying the design and features (X-Cart 5)
 
Thread Tools Search this Thread
  #1  
Old 05-05-2015, 02:30 PM
  RichieRich's Avatar 
RichieRich RichieRich is offline
 

X-Adept
  
Join Date: Sep 2004
Location: London, England
Posts: 750
 

Post Truncate product title in XC5

Does anybody know how to truncate the product title in XC5? Thanks in advance

I am talking about the /default/en/items_list/product/parts/common_product_name.tpl
__________________
Richard


Ultimate 5.4 testing
Reply With Quote
  #2  
Old 05-05-2015, 03:42 PM
  totaltec's Avatar 
totaltec totaltec is offline
 

X-Guru
  
Join Date: Jan 2007
Location: Louisville, KY USA
Posts: 5,823
 

Default Re: Truncate product title in XC5

Probably best done in PHP. I can't find any reference or example of a title being truncated in a template.
__________________
Mike White - Now Accepting new clients and projects! Work with the best, get a US based development team for just $125 an hour. Call 1-502-773-6454, email mike at babymonkeystudios.com, or skype b8bym0nkey

XcartGuru
X-cart Tutorials | X-cart 5 Tutorials

Check out the responsive template for X-cart.
Reply With Quote
  #3  
Old 05-05-2015, 03:47 PM
  RichieRich's Avatar 
RichieRich RichieRich is offline
 

X-Adept
  
Join Date: Sep 2004
Location: London, England
Posts: 750
 

Default Re: Truncate product title in XC5

Ah ok thanks mike, I was wondering the same thing, shame it can't be done in the template like before
__________________
Richard


Ultimate 5.4 testing
Reply With Quote

The following user thanks RichieRich for this useful post:
totaltec (05-05-2015)
  #4  
Old 05-05-2015, 03:48 PM
  totaltec's Avatar 
totaltec totaltec is offline
 

X-Guru
  
Join Date: Jan 2007
Location: Louisville, KY USA
Posts: 5,823
 

Default Re: Truncate product title in XC5

Okay here you go.

I decorated XLite/Model/Product (though there might be a better class, I just went straight to the source)

Added this method:
Code:
/** * Get truncated name * * @return string */ public function getTruncatedName() { $name = $this->getSoftTranslation()->getName(); return substr($name, 0, 10); }

And then refernced it in a template like this:
Code:
{product.getTruncatedName()}

There might be a more flexible truncation function in PHP, but substr() is the only one I am familiar with.

Quick search just turned this up: http://stackoverflow.com/questions/9219795/truncating-text-in-php

So maybe substr is the best way. If you need more control look at the second option there with a pretty little truncate function.
__________________
Mike White - Now Accepting new clients and projects! Work with the best, get a US based development team for just $125 an hour. Call 1-502-773-6454, email mike at babymonkeystudios.com, or skype b8bym0nkey

XcartGuru
X-cart Tutorials | X-cart 5 Tutorials

Check out the responsive template for X-cart.
Reply With Quote

The following user thanks totaltec for this useful post:
RichieRich (06-02-2015)
  #5  
Old 05-05-2015, 04:01 PM
  totaltec's Avatar 
totaltec totaltec is offline
 

X-Guru
  
Join Date: Jan 2007
Location: Louisville, KY USA
Posts: 5,823
 

Default Re: Truncate product title in XC5

Quote:
Originally Posted by RichieRich
Ah ok thanks mike, I was wondering the same thing, shame it can't be done in the template like before
Not really. Yes it's a bit of a pain when looking for the quick fix. But the separation of logic from presentation is the holy grail of program design.

With Smarty(XC4 template engine), we got some of that separation, but not nearly enough. I'm not a mind reader, but if I put myself in the position of the devs behind Flexy (XC5 template engine); I can see them being determined to not let Flexy turn into the mess that Smarty did.

Smarty gave designers too much power. And so rather than learn some PHP or bring in a dev, they just implemented some code in Smarty that "took care of it". Even if "taking care of it" meant 20 nested foreach loops.

This is the better way. But the learning curve is frightful for some.

A real world example of how this is better, even from a designer's standpoint: Now you have truncated the product name in 20 different templates with a Smarty call to {$product.name|truncate:30:"...":true}. And your client says "What the heck are those three dots at the end? I want those removed". You now have 20 edits to make. With a PHP method/function it's just one change.

Yeah I may be reaching with this example, but it demonstrates the point perhaps.
__________________
Mike White - Now Accepting new clients and projects! Work with the best, get a US based development team for just $125 an hour. Call 1-502-773-6454, email mike at babymonkeystudios.com, or skype b8bym0nkey

XcartGuru
X-cart Tutorials | X-cart 5 Tutorials

Check out the responsive template for X-cart.
Reply With Quote
  #6  
Old 05-06-2015, 02:53 AM
  tony_sologubov's Avatar 
tony_sologubov tony_sologubov is offline
 

X-Cart team
  
Join Date: Jan 2009
Posts: 2,430
 

Default Re: Truncate product title in XC5

@Mike, here is a way of truncating a string and having full words:
http://stackoverflow.com/a/79986/4634288
__________________
Found a bug in X-Cart? Post it to our bug tracker!
Know how to make X-Cart better? Suggest an idea!
Reply With Quote

The following user thanks tony_sologubov for this useful post:
totaltec (05-06-2015)
Reply
   X-Cart forums > X-Cart 5 > Modifying the design and features (X-Cart 5)


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 09:09 AM.

   

 
X-Cart forums © 2001-2020