-1

Situation: PHP-based CMS (OpenCart 2.0.3.1) -> category page -> outputs the product names via: <?php echo $product['name']; ?>

Problem: need to wrap a portion of the product name, to the next line. For example, what currently displays as 20-inch Blue Widget For Golfers should display as

20-inch Blue
Widget for Golfers

So every product that has the word "Widget" (or "AnotherKeyword" in it), should have a <br> before it.

How can this be done?

P.S. Changing the product name itself to include a <br> or &lt;br&gt; doesn't work, since OpenCart displays whatever is in the Product Name field literally, ignoring HTML. (Unless someone can point me in the direction of "how to echo the $product[name] but actually process the HTML in it").

HDP
  • 4,005
  • 2
  • 36
  • 58
TomJones999
  • 775
  • 2
  • 13
  • 30
  • 3
    Replace `widget` with `
    widget`?
    – u_mulder Jan 06 '17 at 19:00
  • @u_mulder He says that won't work, because it displays the element literally, not as HTML. – Barmar Jan 06 '17 at 19:07
  • It sounds like it actually outputs it as `echo htmlentities($product['name'])`. Unless there's a way for you to wrap the whole thing in an element like `
    `, I'm not sure there's any way for you to add line breaks to it.
    – Barmar Jan 06 '17 at 19:09
  • @Barmar I suppose template can be modified somehow. Otherwise - what OP can change without accessing a template? – u_mulder Jan 06 '17 at 19:14
  • I can change the template, I have full access to all the core files. I just don't know how to implement this particular change. – TomJones999 Jan 06 '17 at 20:21
  • The entire line that controls the output of the product name is: `

    ` ...unless I can somehow change the `echo $product['name']` to process the HTML tags? That would solve my problem, as a work-around. (I would still have to insert the "
    " into every product name, but it's doable). I would prefer to have a solution that doesn't involve adding extra junk into the actual product data though...
    – TomJones999 Jan 06 '17 at 20:23

1 Answers1

0

As suggested, you can first replace in php "Widget" with a br in front and then via jquery wrap all this way:

<script>
    $(".name a").text(function () {
        $(this).wrap('<pre />');
    })
</script>