When i create static block magento wraps content with <p>
tags. Which is very bad for DOM.
Is is possible to remove it somehow. I suppose it is some javascript but i don't know which one.
Actually wrong on my earlier answer.
You need to turn the static block WYSIWYG editor off-by-default.
Go to System -> Configuration, find General section on left hand side, click on Content Management and set 'Enable WYSIWYG Editor' to 'Disable by default' from list.
Then edit your static blocks carefully - use the WYSIWYG but check your HTML afterwards.
This behaviour is a standard feature of WYSIWYG editors, that is what they are for, the <p>
tags are added in because they make nicely formatted text. Clearly this is not what you want if you add a static block containing just an image, so step out of the editor and check for <p>
tags.
The WYSIWYG editor can also mangle variables entered into the static blocks, and it slows down admin page load times, therefore it is best to have it turned off by default.
A more user-friendly method would be to catch the cms_page_render
-event, and use a regular expression to 'unwrap' the widget:
config:
<cms_page_render>
<observers>
<your_unique_handler>
<type>singleton</type>
<class>Package_Module_Model_Observer</class>
<method>cmsPageRenderEvent</method>
</your_unique_handler>
</observers>
</cms_page_render>
observer:
public function cmsPageRenderEvent($observer)
{
/* @var $page Mage_Cms_Model_Page*/
$page = $observer->getPage();
// Remove wrapping paragraphs around widgets:
$content = $page->getContent();
$content = preg_replace('/\<p\>{{(.*?)}}\<\/p\>/', '{{$1}}', $content);
$page->setContent($content);
}
This would unwrap the widget out of their paragraphs prior to Magento's execution of them.
Edit: the part between {{ and }} should be non-greedy.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With