在自定义页面Magento上显示自定义静态块

在自定义页面Magento上显示自定义静态块,magento,content-management-system,block,frontend,routes,Magento,Content Management System,Block,Frontend,Routes,我对自定义页面上显示的Magento cms静态块有一些疑问。 例如,我有3个静态块(块1、块2、块3),我需要在类别1和子类别1显示块1,在类别2和子类别2显示块2,在其他页面(主页、关于等)显示块3 我尝试使用Mage::app()->getFrontController()->getRequest()->getRequestUri() 但我收到了像“category1.html”这样的请求,若我们转到这个category的子类别,那个么块将更改为默认值 如果使用Mage::app()->g

我对自定义页面上显示的Magento cms静态块有一些疑问。 例如,我有3个静态块(块1、块2、块3),我需要在类别1和子类别1显示块1,在类别2和子类别2显示块2,在其他页面(主页、关于等)显示块3

我尝试使用
Mage::app()->getFrontController()->getRequest()->getRequestUri()

但我收到了像“category1.html”这样的请求,若我们转到这个category的子类别,那个么块将更改为默认值

如果使用
Mage::app()->getFrontController()->getRequest()
我收到了“目录/类别/视图/标识/标识号”

我真的不明白如何解决这个问题


谢谢你的回答

覆盖本地模块中的catalog.xml 附加 内容参考

在目录/category/voew.phtml中 添加此代码

$\u current\u category=$this->getCurrentCategory()

如果(条件==‘第一类’){ echo$this->getChildHtml('block1'); }


类似地,对于其他块

您可以使用Magento提供的内置功能将静态块分配给特定类别

  • 转到目录>管理类别
  • 单击左侧要将块指定给的类别
  • 转到显示设置选项卡
  • 显示模式设置为
    仅静态块
    带产品的静态块
  • 将CMS块设置为要在此类别上显示的静态块
  • 单击保存类别按钮

  • 对不同类别重复此步骤。您可以选择一个唯一的静态块,或通过这种方式将同一块分配给多个类别。

    您可以使用自定义布局更新功能为特定类别向页面的特定部分添加块

    注意:如果您有自定义主题,页脚的引用名称可能不同。此方法已在Magento附带的现代主题上进行了测试

  • 转到目录>管理类别
  • 选择要将块指定给的类别
  • 转到自定义设计选项卡
  • 使用父类别设置设置设置为
    No
  • 在自定义布局更新中插入以下XML

    我的页脚块


  • my\u footer\u块
    替换为静态块的标识符(块id)

  • 清除系统>缓存管理下的Magento缓存并刷新类别页面
  • 如果这不起作用,则引用名称可能不适合您正在使用的主题。您可以通过查看
    app/design/frontend/[THEME PARENT]/[THEME CHILD]/layout/page.xml
    并在文件中搜索
    page/html\u footer
    来检查引用名称

    在该文件中,您会发现如下内容:

    <block type="page/html_footer" name="footer" as="footer" template="page/html/footer.phtml">
        <block type="page/html_wrapper" name="bottom.container" as="bottomContainer" translate="label">
            <label>Page Footer</label>
            <action method="setElementClass"><value>bottom-container</value></action>
        </block>
        <block type="page/template_links" name="footer_links" as="footer_links" template="page/template/links.phtml"/>
            <block type="page/switch" name="store_switcher" as="store_switcher" template="page/switch/stores.phtml"/>
        </block>
        <block type="core/text_list" name="before_body_end" as="before_body_end" translate="label">
            <label>Page Bottom</label>
        </block>
    </block>
    
    
    页脚
    底部容器
    页面底部
    
    请注意
    page/html\u包装器
    块的
    name
    属性。这是步骤步骤5中提供的代码中使用的名称引用。如果它与
    bottom.container
    不同,请更改
    bottom.container
    以匹配page.xml文件中的内容。

    这可能会对您有所帮助

    Strategy : Check current page is whether current category is available on current page or not, If available then you can check it's level and depending on that you can show you block
    
    Solution :
    $_current_category=$this->getCurrentCategory();
    1)get current category and if category not available then show default block
    2)if category found get it's level $_current_category->getLevel() and then you can place your block accordingly
    

    你的问题有点让人困惑。您正在尝试将静态块分配给特定类别吗?是的,我只有3个类别+子类别和其他页面,如主页、配送等,我想显示在管理中创建的3个不同的静态块(cat1+subcat1=block1等)和块4用于其他页面。为什么不能使用内置功能,允许您将静态块分配给类别?我添加了一个答案,概述了执行此操作的步骤。感谢您的回答,但此块需要显示在页脚中。我尝试了此版本,但我需要在页脚中显示当前块。我添加了另一个答案,详细说明了如何执行此操作。今后,请详细说明您试图实现的目标,直至页面上的位置(在您的情况下,类别页脚中的静态块)。这将允许这里的人给你一个正确的答案,你正在努力实现。