VirtueMart Forum

VirtueMart 2 + 3 + 4 => Templating & Layouts => Topic started by: andrew.overlord on December 16, 2012, 23:51:52 PM

Title: Line break in product name or product name with "prefix"
Post by: andrew.overlord on December 16, 2012, 23:51:52 PM
Hi!
Sorry for my bad english)
I got an annoying client, who wants that the product name is displayed in two lines.
Simply can not break product name in two lines.
I thought to add a field in the database (such as "product_name_prefix"), but then I realized that then (with my PHP skills:)) I can not fix the breadcrumbs, aliases, the cart, other modules, etc.

Thanks for any help or idea.
Title: Re: Line break in product name or product name with "prefix"
Post by: bytelord on December 17, 2012, 10:25:26 AM
Hello,

Yes using some PHP to your overridden files, could be like this:

<?php
$title_length
strlen($product->product_name);
echo 
wordwrap($product->product_namefloor($title_length 2),"<br />\n");
?>


Regards
Title: Re: Line break in product name or product name with "prefix"
Post by: andrew.overlord on December 17, 2012, 14:25:02 PM
Thanks a lot, bytelord!
Interesting variant, not perfect but pretty good  :)
Title: Re: Line break in product name or product name with "prefix"
Post by: bytelord on December 17, 2012, 14:30:34 PM
Hello,

You can make it to support hyper-nation but i think this is the best you could done if you want the product title to devide it in two lines, otherwise use some CSS to make the default height of the div that places the title equal to 2 lines.

Regards
Title: Re: Line break in product name or product name with "prefix"
Post by: andrew.overlord on December 17, 2012, 15:57:43 PM
I adjusted a bit the "coefficient" - for my tasks - perfect.
Another: some of the products contain " character (eg Espresso "Premium"), here is the situation easier. I'm using a simple regexp
$regex = '/(\s")/';
if (preg_match($regex, $product->product_name)) {
$product->product_name = preg_replace($regex, "<br/>\n\"", $product->product_name);
} else {
...your code;
}


Thanks for the inspiration!)
Title: Re: Line break in product name or product name with "prefix"
Post by: bytelord on December 17, 2012, 16:03:26 PM
I could say i prefer preg_match/replace also :)

Well done  :)

Regards
Title: Re: Line break in product name or product name with "prefix"
Post by: banik78 on April 08, 2013, 15:25:32 PM
hey, guys, I am looking for a solution on this subject but this doesn't work as I wish. Did you make it work and if yes what is the code? The one you have mentioned brakes every word into a new line. I just want to break it to 2 lines. I really have to fix it, my client is such a b..ch. Thanks.