php 如何在cms页面中调用phtml文件来设置页面标题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17500362/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 13:01:24  来源:igfitidea点击:

How to call a phtml file in cms page to set page title

phpmagento

提问by sam

In Magento how to call a phtml file in cms page to set page title which title I set in my phtml file? I am using

在Magento中如何调用cms页面中的phtml文件来设置页面标题我在我的phtml文件中设置的标题?我在用

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

to set page title.

设置页面标题。

回答by

To call a phtml file in a cms page or cms static block:

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

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

If you know, where the block file(php file) for your phtml file resides, then you can use it as type.

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

Example:Suppose you want to call new.phtml file that resides in catalog/product folder, and you know that its corresponding Block file(php file) resides in Catalog/Product folder, then you can use:

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

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

More reading: here

更多阅读:这里

Hope this helps!

希望这可以帮助!

回答by Marius

You cannot change the title of the page from a template file when using it in a cms block or cms page because the headblock is already rendered when the page (or block) content is parsed.

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

回答by Anil Gupta

It's not possible to change page title from phtml file of cms pages as already told by @Marius

正如@Marius 已经告诉的那样,无法从 cms 页面的 phtml 文件更改页面标题

you need to add to it's design in cms page as given below :

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

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

回答by Shivani

Add the below XML piece under CMS > Pages > Manage Content > Select a specific CMS Page

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

Navigate to "Design" tab > Layout Update XML >

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

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

Make sure the CACHE folders are DELETED under below: {Root Magento Folder}/var/cache {Root Magento Folder}/var/full_page_cache

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

Hope this helps!

希望这可以帮助!

Happy Coding...

快乐编码...