我在CMS->页面"主页"文件中.在内容我写这样的行:
{{block type="myfolder/newfile" template="myfolder/newfile.phtml"}}
Run Code Online (Sandbox Code Playgroud)
我想在内容文件newfile.phtml中呈现.我做错了什么?
我的新文件位于:app\design\frontend\default\themeas\template\myfolder \newfile.phtml
Ant*_*ond 22
你需要给你的块命名.这就是Magento将如何引用该块.此外,块类型必须有效才能生成块.对于默认块,请尝试使用type ="core/template"
您的新代码应如下所示:
{{block type="core/template" name="my.block.name" template="myfolder/newfile.phtml"}}
Run Code Online (Sandbox Code Playgroud)
另一个关于type属性的注释,它实际上不是一个目录/文件结构,而是一个用Magento自动加载器映射的URI."Core"与Mage_Core_Block_Core类(在app/code/core/Mage/Core目录下)有关,然后斜杠后面的信息与该目录内的文件夹有关.因此type ="core/template"解析为此类Mage_Core_Block_Core_Template,它位于app/code/core/Mage/Core/Block/Template.php.所有类型属性都在告诉Magento您需要在块内加载哪些方法.
您可以尝试的其他几种块类型是:
对于产品列表:catalog/product_list
对于文本列表(自动呈现子块的块):core/text_list
对于类别块:catalog/category_view
还有更多,找到新的方法的好方法是查看与您尝试执行类似操作的块,并找到在XML中定义的位置.
如果要将变量传递给块,可以执行以下操作:
{{block type="core/template" name="my.block.name" myvariable="5" template="myfolder/newfile.phtml"}}
Run Code Online (Sandbox Code Playgroud)
小智 5
从 Magento 1.9.2.2 或等效补丁开始,您还需要向新块授予权限。您在后端执行此操作:System | 权限 | 块
即,如果您想显示:
{{block type="catalog/product_bestseller" name="krillo.bestseller" template="catalog/product/bestseller.phtml"}}
Run Code Online (Sandbox Code Playgroud)
添加您的块名称“catalog/product_bestseller”并将状态设置为“允许”
归档时间: |
|
查看次数: |
35415 次 |
最近记录: |