Magento editor automatic line break issue while ad

2019-05-17 12:18发布

问题:

I'm adding a new product in Magento CE 1.7.0.2. I entered the HTML code in Short Description attribute.

MY PROBLEM: I really don't know where these extra <br> coming from. Even the WYSIWYG editor is not showing these <br> but they are appearing on the website's product page. Please help.

WHAT I ENTERED:

<p>Product Description:</p>
<table border="1" cellspacing="0" cellpadding="5px">
    <tr>
        <td>Category</td>
        <td>Specials</td>
    </tr>
    <tr>
        <td>Texure</td>
        <td>Digitally Printed on High Quality Matte Paper</td>
    </tr>
</table>

WHAT IT IS DISPLAYING:

<p>Product Description:</p>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<table border="1" cellspacing="0" cellpadding="5px">
    <tr>
        <td>Category</td>
        <td>Specials</td>
    </tr>
    <tr>
        <td>Texure</td>
        <td>Digitally Printed on High Quality Matte Paper</td>
    </tr>
</table>

回答1:

I have found the answer on this link.



回答2:

These additional breaks are caused by nl2br() function that should be removed.

To resolve this for short description, open app/design/frontend/[package]/[theme]/template/catalog/product/view.phtml, find:

<?php echo $_helper->productAttribute($_product, nl2br($_product->getShortDescription()), 'short_description') ?>

and replace this by:

<?php echo $_helper->productAttribute($_product, $_product->getShortDescription(), 'short_description') ?>

To resolve this for description, open app/design/frontend/[package]/[theme]/template/catalog/product/view/description.phtml, find:

<?php echo $this->helper('catalog/output')->productAttribute($this->getProduct(), nl2br($_description), 'description') ?>

and relace this by:

<?php echo $this->helper('catalog/output')->productAttribute($_product, $_product->getDescription(), 'description') ?>

Source