【问题标题】:How to call a phtml file in cms page to set page title如何在cms页面中调用phtml文件来设置页面标题
【发布时间】:2013-07-06 06:30:10
【问题描述】:

在 Magento 中,如何在 cms 页面中调用 phtml 文件来设置页面标题,我在 phtml 文件中设置了哪个标题?我正在使用

$this->getLayout()->getBlock('head')->setTitle('your title'); 

设置页面标题。

【问题讨论】:

    标签: php magento


    【解决方案1】:

    在 cms 页面或 cms 静态块中调用 phtml 文件:

    {{block type="core/template" template="templateFolder/your_template.phtml"}}
    

    如果您知道 phtml 文件的块文件(php 文件)所在的位置,那么您可以将其用作类型。

    示例: 假设你要调用位于catalog/product 文件夹下的new.phtml 文件,并且你知道它对应的Block 文件(php 文件)位于Catalog/Product 文件夹下,那么你可以使用:

    {{block type="catalog/product" template="catalog/product/new.phtml"}}
    

    更多阅读:here

    希望这会有所帮助!

    【讨论】:

      【解决方案2】:

      在 cms 块或 cms 页面中使用模板文件时,您无法更改页面的标题,因为在解析页面(或块)内容时已经呈现 head 块。

      【讨论】:

        【解决方案3】:

        正如@Marius 所说,无法从 cms 页面的 phtml 文件中更改页面标题

        您需要在 cms 页面中添加它的设计,如下所示:

        <reference name="head">
           <action method="setCustomTitle" translate="title"> <title> Custom Title </title> </action>
        </reference>
        

        【讨论】:

          【解决方案4】:

          在 CMS > 页面 > 管理内容 > 选择特定的 CMS 页面下添加以下 XML 片段

          导航到“设计”选项卡 > 布局更新 XML >

           <reference name="head">
               <action method="setCustomTitle" translate="title"> <title> Custom Title  </title> </action>
           </reference>
          

          确保以下 CACHE 文件夹已删除: {根 Magento 文件夹}/var/cache {根 Magento 文件夹}/var/full_page_cache

          希望这会有所帮助!

          快乐编码...

          【讨论】:

            猜你喜欢
            • 2012-09-30
            • 2015-03-21
            • 1970-01-01
            • 1970-01-01
            • 2017-01-17
            • 1970-01-01
            • 1970-01-01
            • 2016-03-21
            • 2016-09-19
            相关资源
            最近更新 更多