How to remove <br /> added by magento.
Posted Tue, 02/16/2010 - 10:10am
In case you're wondering why your product description is all spaced out, then that's because magento is adding automatic line breaks into the content description area...
To get rid of it... look for
nl2brspecifically in description.phtml you'll see
<div class="std">
<?php echo $this->helper('catalog/output')->productAttribute($this->getProduct(), nl2br($this->getProduct()->getDescription()), 'description') ?>
</div>it should look like this after you take the nl2br out:
<div class="std">
<?php echo $this->helper('catalog/output')->productAttribute($this->getProduct(), ($this->getProduct()->getDescription()), 'description') ?>
</div>Noticed that Magento 1.4.1 has this structured a little differently. It has the line breaks already turned off--doesn't include nl2br, and rather uses a built in WYSIWYG editor for the description section.
If you want to go back to the old way of line breaks, and don't want to use the WYSIWYG editor. E.g. you have a site that already has it's products input the old way (in this case, the formatting would be lost, so you'd have to redo all descriptions using WYSIWYG... and if you have a lot of products this can take very long)
anyhow...
I copied description.phtml from the base directory into my custom template one (base always has the latest version template files--which get changed often when upgrading)
app/design/frontend/base/default/template/catalog/product/view/description.phtmlbefore
<?php $_description = $this->getProduct()->getDescription(); ?>
<?php if ($_description): ?>
<h2><?php echo $this->__('Details') ?></h2>
<div class="std">
<?php echo $this->helper('catalog/output')->productAttribute($this->getProduct(), $_description, 'description') ?>
</div>
<?php endif; ?>after
<?php $_description = $this->getProduct()->getDescription(); ?>
<?php if ($_description): ?>
<h2><?php echo $this->__('Details') ?></h2>
<div class="std">
<?php echo $this->helper('catalog/output')->productAttribute($this->getProduct(), nl2br($_description), 'description') ?>
</div>
<?php endif; ?>
Comments
Thanks for the tip...
by Anonymous - 02/16/2010 - 10:16am
Thanks for the tip...
very useful!
by Owen - 04/06/2010 - 4:37pm
thanks for this useful post! i fix the problem,it looks pretty good now!
thanks again!
It simply doesn't work! I
by David - 04/19/2010 - 11:18am
It simply doesn't work! I tried to remove that part of the code and it is still the same. Still having 's in every description!
Problem Fixed! (Note: DIDN'T
by David - 04/19/2010 - 11:53am
Problem Fixed! (Note: DIDN'T CHANGED ANYTHING IN THE .PHP FILE or ANYWHERE ELSE AS BEING SUGGESTED IN MANY PLACES)
Went to in Admin
In Catalog>Attributes>Manage Attributes look for "Description" and "Short Description" attributes. Once in look for "Enable WYSIWYG" option and select "Yes".
That's it!
(The above suggestions with the code editing, etc. may work if you do not have any attributes installed. If you do, don't bother.)
If that removes the generated
by duntuk - 04/20/2010 - 6:16pm
If that removes the auto-generated line breaks in code while inputing custom/advanced HTML, then that would work.
However, with your suggestion, enabling the WYSIWYG editor, logic would state that would only make things worse--i.e. one would turn off the the WYSIWYG editor to do hand coded (custom) HTML, not turn it on. WYSIWYG does exactly what this suggestion is trying to prevent, it automatically ads HTML line breaks/paragraphs during carriage returns.
btw, you have to make sure
by duntuk - 04/20/2010 - 8:00pm
btw, you have to make sure you're editing the currently used theme.
Thanks, works perfectly!
by Elijah - 06/09/2010 - 3:08am
Thanks, works perfectly!
Thank you mang. Wondering
by Anonymous - 01/05/2011 - 11:45am
Thank you mang. Wondering wtf the deal was with that. Thank you!!!
Thank you so much! this will
by Niz - 01/25/2011 - 11:53am
Thank you so much! this will save me hours if not days, removing formating.
Godspeed ;)
Thank you! My product view
by karser - 03/24/2011 - 2:56pm
Thank you! My product view description looks so awesome now! http://magazento.com/english/magento-ext/magazento-extensions/magazento-anyslider
Very Good
by ravi - 04/09/2011 - 10:57am
Very Good article
Thanks
JeevanSathi
really thanks for the help
by canada goose - 09/01/2011 - 11:48am
really thanks for the help
Works perfectly!
by professionele webshop - 09/09/2011 - 6:04am
Works perfectly!
This is an excellent post. I
by Web Designer - 09/16/2011 - 12:11am
This is an excellent post. I really appreciate with you. I enjoyed the post. Thanks for sharing.
Very usefull!
by marcel - 11/18/2011 - 1:14am
Very usefull!
Hi, I was dealing with this
by Magento webshop - 12/09/2011 - 2:28am
Hi, I was dealing with this problem as well, but was able to resolve the problem after a while. Good post though
A better way would be to add
by Christian - 01/30/2012 - 2:52pm
A better way would be to add an attribute to every attribute set and placed just under the Description text box, called IsHTMLDescription.
Then you can declare if the description is simply text, or html code.
Inside description.phtml ive got
<?php
$is_html_desc
= $this->getProduct()->getAttributeText('is_html_description');if ($is_html_desc == "Yes")
echo $this->helper('catalog/output')->productAttribute($this->getProduct(), $_description, 'description');
else
echo nl2br($this->helper('catalog/output')->productAttribute($this->getProduct(), $_description, 'description'));
?>
Post new comment