Magento createBlock 方法不起作用,显示静态块数据
好的,我已经在我的 CMS 区域中创建了静态块,并且我尝试将它们输出到我构建的自定义主页模板中。
我能找到的每个文档都说按如下方式输出块
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('my-block-identifier')->toHtml() ?>
这对我不起作用,所以我尝试了另一种方法。 --
<?php $block = Mage::getSingleton('core/layout')->createBlock('cms/block')->setBlockId('my-block-identifier');
echo $block->toHtml();
所有引用此内容的站点都告诉我使用实际的块标识符来获取块。因此,我决定在 cms_block 表中手动查找 block_id,看看使用 block_id 数字代替文字 my-block-identifier 名称是否有效 - 确实如此。所以我很困惑...谁能告诉我如何通过实际标识符获取块,或者通过标识符查找块ID,以便我可以通过块名称获取块?
非常感谢任何帮助。
Ok so Ive created static blocks in my CMS area, and Im trying to output them inside of a custom homepage template Ive built.
Every document I can find says to output the block as follows
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('my-block-identifier')->toHtml() ?>
That didnt work for me, so then I tried another way. --
<?php $block = Mage::getSingleton('core/layout')->createBlock('cms/block')->setBlockId('my-block-identifier');
echo $block->toHtml();
All the sites referencing this tell me to use the actual blocks identifier to get the block. So then I decide to manually lookup the block_id in my cms_block table and see if using the block_id number in place of the literal my-block-identifier name will work - and it did. So I am confused... Can anyone tell me how I can get the block by the actual identifier, or look up the blocks id by the identifier so that I can grab the block by block name?
Any help much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
查看
cms/block
块源代码,那些教程误导了您,或者您误解了它们。块内容始终通过
->load($blockId);
加载 - 带一个参数的load
始终意味着通过数据库 ID 加载。因此,由于块中没有内置支持的方法,您需要查找块 ID。
Looking at the
cms/block
block source, those tutorials have mislead you, or you misinterpreted them.The block content is always loaded with
->load($blockId);
--load
with one parameter always means loding by a database ID.So, with no supported way of doing this built into the block, you'll need to look up the block ID.
在管理中,当您编辑静态块的内容时,您将看到一个名为“标识符”的字段,从顶部数第二个。复制该字段的值,并将其插入到您的代码中。因此,如果您的块在管理员中称为
contact-info
,那么您的代码将如下所示:管理员中标识符文本框中的值也将被保存到
cms_block
中代码>表,正如你所计算的那样。哈特哈,
京东
In the admin, when you are editing the contents of the static block, you will see a field called Identifier second from the top. Copy the value of that field, and insert it into your code. So if your Block is called
contact-info
in the admin, then your code will look like:The value in that Identifier textbox in the admin is also what will be saved into the
cms_block
table, as you're worked out.HTH,
JD