XML 布局中的 Magento 静态 CMS 块具有两个或多个商店视图

发布于 2024-11-16 19:34:10 字数 818 浏览 3 评论 0原文

我有两个名为“promo_en”和“promo_de”的静态 CMS 块 - 翻译为两个现有的商店视图“en”和“de”。

我想使用模块的layout.xml 文件将它们添加到某些模块的侧边栏。

问题是,如果我使用以下语法添加它们 - 它们都显示忽略我当前所在的商店视图(我希望进行一些自动过滤):

<block type="cms/block" name="Promo_de">
    <action method="setBlockId"><block_id>promo_de</block_id></action>
</block> 
<block type="cms/block" name="Promo_en">
    <action method="setBlockId"><block_id>promo_en</block_id></action>
</block> 

如果我将它们都重命名为“promo”并使用以下语法 - 它工作正常,直到我激活 Magento 的缓存 - 然后 CMS 块的输出会冻结在首先缓存的任何 storeview 上:

<block type="cms/block" name="Promo">
    <action method="setBlockId"><block_id>promo</block_id></action>
</block> 

并且高度赞赏有关此事的想法或解决方法。

I have two static CMS Blocks called "promo_en" and "promo_de" - translated for the two existing storeviews "en" and "de".

I'd like to add them to the sidebar of some modules using the layout.xml files of the modules.

The problem is that if I add them both using the following syntax - they both show disregarding the storeview I'm currently in (I would expect some automatic filtering):

<block type="cms/block" name="Promo_de">
    <action method="setBlockId"><block_id>promo_de</block_id></action>
</block> 
<block type="cms/block" name="Promo_en">
    <action method="setBlockId"><block_id>promo_en</block_id></action>
</block> 

If I rename them both to "promo" and use the following syntax - it works fine until I activate Magento's cache - then the output of the CMS block freezes on whatever storeview is cached first:

<block type="cms/block" name="Promo">
    <action method="setBlockId"><block_id>promo</block_id></action>
</block> 

And ideas or workarounds on the matter are highly appreciated.

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

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

发布评论

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

评论(3

じее 2024-11-23 19:34:10

作为一个粗略的解决方法,您可以使用特定于每个商店的布局句柄。例如;

<STORE_de>
    <reference name="left">
        <block type="cms/block" name="Promo_de">
            <action method="setBlockId"><block_id>promo_de</block_id></action>
        </block> 
    </reference>
</STORE_de>
<STORE_en>
    <reference name="left">
        <block type="cms/block" name="Promo_en">
            <action method="setBlockId"><block_id>promo_en</block_id></action>
        </block> 
    </reference>
</STORE_en>

As a rough workaround you can use layout handles specific to each store. For example;

<STORE_de>
    <reference name="left">
        <block type="cms/block" name="Promo_de">
            <action method="setBlockId"><block_id>promo_de</block_id></action>
        </block> 
    </reference>
</STORE_de>
<STORE_en>
    <reference name="left">
        <block type="cms/block" name="Promo_en">
            <action method="setBlockId"><block_id>promo_en</block_id></action>
        </block> 
    </reference>
</STORE_en>
单身狗的梦 2024-11-23 19:34:10

为什么不创建具有相同标识符的静态块,然后仅在相应的商店视图中启用它们?

<block type="cms/block" name="Promo">
    <action method="setBlockId"><block_id>promo</block_id></action>
</block> 

然后创建 2 个带有标识符 promo 的静态块,并且仅在它们所属的 storeview 中启用它们?

Why not create the static blocks with same identifier, and then only enable them in corresponding store view?

<block type="cms/block" name="Promo">
    <action method="setBlockId"><block_id>promo</block_id></action>
</block> 

Then create 2 static blocks with identifier promo and only enable them in storeview where they belong?

江南烟雨〆相思醉 2024-11-23 19:34:10

我最终编写了自己的迷你模块来快速解决问题,根据当前的商店代码切换代码中的翻译:

if( Mage::app()->getStore()->getCode() == 'de' ) 
{
    echo $this->getLayout()->createBlock('cms/block')->setBlockId('promo_de')->toHtml();
} 
else if( Mage::app()->getStore()->getCode() == 'en' ) 
{
    echo $this->getLayout()->createBlock('cms/block')->setBlockId('promo_en')->toHtml();
}

我知道这很丑陋,但时间确实是一个问题,我将来必须清理它。 ..

I ended up writing my own Mini-Module to quickfix the problem, switching the translations in code based on the current store code:

if( Mage::app()->getStore()->getCode() == 'de' ) 
{
    echo $this->getLayout()->createBlock('cms/block')->setBlockId('promo_de')->toHtml();
} 
else if( Mage::app()->getStore()->getCode() == 'en' ) 
{
    echo $this->getLayout()->createBlock('cms/block')->setBlockId('promo_en')->toHtml();
}

I know it's ugly but time really was an issue here and I'll have to clean this up in the future...

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