View Single Post
  #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