php 想使用锚标记在另一个 phtml 文件中调用一个 phtml 文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16691546/
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 11:33:16  来源:igfitidea点击:

want to call one phtml file in another phtml file using anchor tag

phpmagentohyperlink

提问by Bhavik Shah

I'm using Magento.

我正在使用 Magento。

I want display and call one phtmlfile as a link in another phtmlfile…

我想显示和调用一个phtml文件作为另一个phtml文件中的链接......

I have the new.phtmlfile on the home page. On that I put one link CHECK ALL which display all new products as category page.. It looks like category page. For that I create another phtmlfile named newproductpage.phtmlwhich has same code of new.phtml. Now I try to call this newproductpage.phtmlfile @homepage as CHECK ALL link for that I write this code....

new.phtml在主页上有文件。在那我放了一个链接CHECK ALL,它显示所有新产品作为类别页面..它看起来像类别页面。为此,我创建了另一个phtml名为的文件newproductpage.phtml,该文件具有相同的new.phtml. 现在我尝试将此newproductpage.phtml文件@homepage 称为检查所有链接,因为我编写了此代码....

<a href="<?php echo $this->getUr('newproductpage.phtml')?>">CHECK ALL</a>

But its not working....

但它不起作用......

thnx..

谢谢..

回答by Deepak Mallah

you call newproductpage.phtml in any phtml file using below code

您使用以下代码在任何 phtml 文件中调用 newproductpage.phtml

<?php echo $this->getLayout()->createBlock('core/template')->setTemplate('custom/newproductpage.phtml')->toHtml(); ?>

回答by Abhinav Kumar Singh

Use the below code for rendering your phtml file in another phtml file.

使用以下代码在另一个 phtml 文件中呈现您的 phtml 文件。

<?php echo $this->getLayout()->createBlock('core/template')->setTemplate('templatefolderpath/filename.phtml')->toHtml(); ?>

For more refinement of your code, you can use the block name and block file name instead of core/template because core/template use the core resources.

为了进一步优化您的代码,您可以使用块名称和块文件名而不是核心/模板,因为核心/模板使用核心资源。

回答by Mufaddal

You can not call directly one phtml file to another phtml file.

您不能直接将一个 phtml 文件调用到另一个 phtml 文件。

But there are two way to call your phtml file either create one controller and create one action and call action from your anchor tag or create one cms page which call your phtml file.

但是有两种方法可以调用您的 phtml 文件,一种是创建一个控制器并创建一个操作并从您的锚标记调用操作,另一种是创建一个调用您的 phtml 文件的 cms 页面。

if you create one module, so in your layout file something you can write

如果你创建一个模块,那么在你的布局文件中你可以写一些东西

<modulename_controllername_controlleraction>
    <reference name="content">
        <block type="catalog/product_new" template="custom/newproductpage.phtml" />
    </reference>
</module_controllername_controlleraction>

Or you can directly put this code in your cms page content area

或者你可以直接把这段代码放到你的cms页面内容区

{{block type="catalog/product_new" template="custom/newproductpage.phtml"}}

and in anchor tag give cms page link.

并在锚标记中给出 cms 页面链接。

回答by Amir Iqbal

<?php echo $this->getLayout()->createBlock('core/template')->setTemplate('catalog/product/new.phtml')->toHtml(); ?>

you can also check the link.

您也可以查看链接。

Display .phtml page in another .phtml page

在另一个 .phtml 页面中显示 .phtml 页面

回答by max7

I believe you and I want to do precisely the same thing. I'm creating a modal from bootstrap and I need to call in a partial using the href attr.

我相信你我都想做同样的事情。我正在从引导程序创建一个模态,我需要使用 href attr 调用部分。

So far, I think this might be possible by creating a page in the CMS and then using something like this:

到目前为止,我认为这可以通过在 CMS 中创建一个页面然后使用如下内容来实现:

<li><a href="<?php echo $this->getUrl("page-name-in-CMS") ?>">Home</a></li>

But honestly, I'm just starting out with Magento and know very little.

但老实说,我刚刚开始使用 Magento,并且知之甚少。

回答by Ganesh Bora

you can use iframe for same and load this another page content using AJAX call

您可以使用 iframe 并使用 AJAX 调用加载另一个页面内容