4

我正在使用magento 1.7。我试图更改 cms 内容的包装,但我仍然无法了解如何更改 cms_page 的包装。

<block type="page/html_wrapper" name="cms.wrapper" translate="label">
    <label>CMS Content Wrapper</label>
    <action method="setElementClass"><value>std</value></action>
    <block type="cms/page" name="cms_page"/>
</block>

和 html 输出是

<div class="std">
    CMS Page content
</div>

但我想这样输出

<section class="std">
    CMS Page Content
</section>

请给我任何解决方案

4

1 回答 1

8

您可以尝试以下代码将 div 更改为 section

<block type="page/html_wrapper" name="cms.wrapper" translate="label">
    <label>CMS Content Wrapper</label>
    <action method="setElementClass"><value>std</value></action>
    <action method="setAttribute"><param1>html_tag_name</param1><param2>section</param2></action>
    <block type="cms/page" name="cms_page"/>
</block>

这会将 div 更改为 section 因为 html_wrapper 类从函数getElementTagName中获取标记名称app\code\core\Mage\Core\Block\Abstract\Wrapper.php

/**
 * Wrapper element tag name getter
 * @return string
 */
public function getElementTagName()
{
    $tagName = $this->_getData('html_tag_name');
    return $tagName ? $tagName : 'div';
}

所以通过调用 setAttribute 我们改变/设置值html_tag_name

于 2013-01-04T08:27:48.697 回答