【问题标题】:Magento - Using same template on mutiple blocks causing errorMagento - 在多个块上使用相同的模板导致错误
【发布时间】:2013-01-24 11:21:26
【问题描述】:

我有 3 个 jQuery 选项卡,并希望用不同类别的产品填充每个选项卡。选项卡显示在类别页面上。在类别页面“自定义布局更新”我有这个:

<block type="catalog/product_list" category_id="38" limit="6" name="tabs_new" template="catalog/product/tab_list.phtml" />
<block type="catalog/product_list" category_id="39" limit="6" name="tabs_topsellers" template="catalog/product/tab_list.phtml" />
<block type="catalog/product_list" category_id="40" limit="6" name="tabs_sale" template="catalog/product/tab_list.phtml" />

tab_list.phtml 只是 list.phtml 的一个副本,去掉了工具栏和一些标记。

在我的类别 view.phtml 文件中,我有以下内容:

<div id="tabs-1">
    <?php echo $this->getChildHtml('tabs_topsellers') ?>
</div>
<div id="tabs-2">
    <?php echo $this->getChildHtml('tabs_new') ?>
</div>
<div id="tabs-3">
    <?php echo $this->getChildHtml('tabs_sale') ?>
</div>

但是当我转到页面时,我得到了这个错误:

Mage registry key "isList" already exists

有什么想法可以做到这一点吗?

【问题讨论】:

    标签: list magento tabs categories product


    【解决方案1】:

    为了快速修复,您可以在回显每个块之前使用Mage::unregister('isList');

    【讨论】:

    • 非常感谢,这完全可以作为快速修复,但最好为我想要实现的目标找到不同的解决方案。不过这很有帮助。
    • 更好的解决方案是不要从模板内部在注册表中写入任何内容,因为这违反了视图和逻辑的分离。不幸的是,Magento 本身在这方面的编码不是很干净。
    【解决方案2】:

    2 个解决方案:

    • 在注册一个值之前,检查它是否已经存在:

      if (!Mage::registry('isList')) { 法师::register('isList'); }

    • 使用Mage::register()函数的第三个参数“$graceful”来忽略现有变量的注册(它不会抛出异常并且什么都不做)

      李>

    【讨论】:

    • 我自己的代码中实际上没有Mage::register('isList');。我唯一做的就是复制并重命名模板文件。
    • 在这个重复的文件(或者它的链接块)中,你有一个 Mage::register I sassume ?
    【解决方案3】:

    太棒了,我在 Ultimo 主题上遇到了类似的问题。

    exception 'Mage_Core_Exception' with message 'Mage registry key "isList" already exists' in /home/devlovethe/public_html/app/Mage.php:595
    

    我试图将 product_list_featured 用于多个类别。

    {{block type="ultimo/product_list_featured" template="catalog/product/list_featured_slider.phtml" category_id="97" product_count="12" breakpoints="[0, 1], [320, 2], [480, 3], [768, 4], [960, 5], [1280, 6]" pagination="1" centered="1" hide_button="1" block_name="Our Featured Products"}}
    

    我在 list_featured_slider.phtml 的末尾添加了

    <?php Mage::unregister('isList'); ?>
    

    【讨论】:

      猜你喜欢
      • 2017-02-17
      • 2017-07-15
      • 2017-09-13
      • 1970-01-01
      • 2016-06-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多