I have a serious issue when displaying trunctuated text such as product description in Featured, Latest, Specials.
When truncating by word count or character count, the results can be disastrous.
If you chop the text between Strong tags, all following on the page text becomes bold. If you use something like color and text is chopped between oping and closing span tags, your page is broken. I have been having this occur because my Latest products occurs before Special priced products, which is in a right column. When this occurs, the complete right column is relocated with the top being located inline with the last line in the offending Latest products display.
This is some code I came up with that will correct the problem. I am going to include somewhere so it will be available anywhere in the catalog. I think it show be a call in locator with the php file somewhere in library. Maybe someone with more experience could offer some suggestions.
This is my fix.
Reduce Text Display
S55-55-675 Cleveland
Outside Lock-up (OLU) : 3.219”
Inside Lock-up (ILU) : 2.380”
Cup Diameter (CD) : 1.063”
Cup Diameter (CD) : 1.125”
Round Cups
Grease-able U-Joint';
$lines = 3; // set $lines for number of complete lines to display
// This function return specified number of lines to display without splitting lines.
// It should handle any formated text. Line count is determined by Line feed tags
// echo formatedstring($test, $lines); // This is call to function, $test is sourcestring, $ lines is number of lines to display
// Will display one line with no trailing dots, more than one includes dots ...(more to come)
function formatedstring ($sourcestring, $lines)
{
if (strpos($sourcestring,'')) {$short = substr($sourcestring,strpos($sourcestring,'')+3,strpos($sourcestring,'')-3);}
else {$short = $sourcestring;}
$short.= '
';
$short = implode('
',array_slice(preg_split('##',$short),0,$lines));
if ($lines > 1){
if (strlen($short) tag is removed
if (strpos($desc,'')) {$desc = substr($desc,0,strpos($desc,''));} // closeing tag removed
if (strlen($desc)
Brent
The most general solution would be to

- count the characters in the actual text without any formatting
- reducing html special characters to count as one
- close all open html tags from the point of truncation

Actually, the function formatedstring ($sourcestring, $lines) does all that.
I have it working with Featured/latest/specials right now.
I was just asking the proper procedure to include in open cart.
Right now, I just have a require_once in each of the module files.
Brent
I have it working with Featured/latest/specials right now.
I was just asking the proper procedure to include in open cart.
Right now, I just have a require_once in each of the module files.
Brent
Brent

I suspect that you are only going to call these functions from within template code so you could put them all into library\template\template.php.
I won't tell you how to set them up as you clearly know PHP quite well.
cheers
Bruce
Well done then...
The location for code depends on where and how it is used. So, if you put a function in library\template\template.php then it will be visible in the .tpl files by name but also accessable from controllers.
eg: in template.php which returns a string value.
is accessed as
or from a controller as follows:
The location for code depends on where and how it is used. So, if you put a function in library\template\template.php then it will be visible in the .tpl files by name but also accessable from controllers.
eg:
Code: Select all
function fred(){...}
is accessed as
Code: Select all
<?php echo fred($product_description); ?>
Code: Select all
$template =& $this->locator->get('template');
$new_description = $template->fred($current_description);
Who is online
Users browsing this forum: No registered users and 1 guest