Magento 静态块。去掉包装纸

发布于 2024-11-15 09:38:04 字数 124 浏览 1 评论 0原文

当我创建静态块时,magento 用

标签包装内容。这对于 DOM 来说非常糟糕。 有可能以某种方式将其删除。我想这是一些 JavaScript,但我不知道是哪一个。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

洋洋洒洒 2024-11-22 09:38:04

我之前的答案实际上是错误的。

您需要默认关闭静态块所见即所得编辑器。

转到系统 ->配置,找到左侧的常规部分,点击内容管理并将“启用所见即所得编辑器”设置为“默认禁用” em> 来自列表。

然后仔细编辑你的静态块 - 使用所见即所得,但之后检查你的 HTML。

此行为是所见即所得编辑器的标准功能,这就是它们的用途,添加

标签是因为它们可以生成格式良好的文本。显然,如果您添加仅包含图像的静态块,这不是您想要的,因此请退出编辑器并检查

标记。

所见即所得编辑器还可以修改输入到静态块中的变量,并且它会减慢管理页面的加载时间,因此最好默认将其关闭。

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.

酒几许 2024-11-22 09:38:04

一种更用户友好的方法是捕获 cms_page_render 事件,并使用正则表达式来“展开”小部件:

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);
}

这会将小部件从 Magento 之前的段落中展开执行他们。

编辑:{{ 和 }} 之间的部分应该是非贪婪的。

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.

情深已缘浅 2024-11-22 09:38:04

编辑js/mage/adminhtml/wysiwyg/tiny_mce/setup.js

var settings = {
        mode : (mode != undefined ? mode : 'none'),
        elements : this.id,
        theme : 'advanced',
        plugins : plugins,
        theme_advanced_buttons1 : magentoPlugins + 'magentowidget,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect',
        theme_advanced_buttons2 : 'cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,forecolor,backcolor',
        theme_advanced_buttons3 : 'tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,iespell,media,advhr,|,ltr,rtl,|,fullscreen',
        theme_advanced_buttons4 : 'insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,pagebreak',
        theme_advanced_toolbar_location : 'top',
        theme_advanced_toolbar_align : 'left',
        theme_advanced_statusbar_location : 'bottom',
        theme_advanced_resizing : true,
        convert_urls : false,
        relative_urls : false,



        forced_root_block : '', /* <-- Add this setting */



        content_css: this.config.content_css,
        custom_popup_css: this.config.popup_css,
        magentowidget_url: this.config.widget_window_url,
        magentoPluginsOptions: magentoPluginsOptions,

edit js/mage/adminhtml/wysiwyg/tiny_mce/setup.js

var settings = {
        mode : (mode != undefined ? mode : 'none'),
        elements : this.id,
        theme : 'advanced',
        plugins : plugins,
        theme_advanced_buttons1 : magentoPlugins + 'magentowidget,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect',
        theme_advanced_buttons2 : 'cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,forecolor,backcolor',
        theme_advanced_buttons3 : 'tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,iespell,media,advhr,|,ltr,rtl,|,fullscreen',
        theme_advanced_buttons4 : 'insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,pagebreak',
        theme_advanced_toolbar_location : 'top',
        theme_advanced_toolbar_align : 'left',
        theme_advanced_statusbar_location : 'bottom',
        theme_advanced_resizing : true,
        convert_urls : false,
        relative_urls : false,



        forced_root_block : '', /* <-- Add this setting */



        content_css: this.config.content_css,
        custom_popup_css: this.config.popup_css,
        magentowidget_url: this.config.widget_window_url,
        magentoPluginsOptions: magentoPluginsOptions,
沦落红尘 2024-11-22 09:38:04

这取决于您在何处使用静态块以及您使用的模板/主题。打开开发人员前端提示,加载有问题的页面,识别使用的模板文件,然后从 phtml 文件中提取

选项卡。

直接调用的静态块不会放入额外的

标签。

This depends on where you are using your static blocks and what templates/theme you are using. Turn on the developer frontend hints, load your offending pages, identify the template file used and then pull out the <p> tabs from your phtml files.

A directly called static block does not put extra <p> tags in.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文