简体   繁体   English

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

[英]want to call one phtml file in another phtml file using anchor tag

I'm using Magento. 我正在使用Magento。

I want display and call one phtml file as a link in another phtml file… 我想显示并调用一个phtml文件作为另一个phtml文件中的链接...

I have the new.phtml file on the home page. 我在new.phtml上有new.phtml文件。 On that I put one link CHECK ALL which display all new products as category page.. It looks like category page. 在那我把一个链接CHECK ALL显示所有新产品作为类别页面..它看起来像类别页面。 For that I create another phtml file named newproductpage.phtml which has same code of new.phtml . 为此,我创建了另一个名为newproductpage.phtml phtml文件,该文件具有相同的new.phtml代码。 Now I try to call this newproductpage.phtml file @homepage as CHECK ALL link for that I write this code.... 现在我尝试将这个newproductpage.phtml文件@homepage称为CHECK ALL链接,因为我编写了这段代码....

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

But its not working.... 但它没有工作......

thnx.. 日Thnx ..

你可以使用下面的代码在任何phtml文件中调用newproductpage.phtml

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

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. 为了更好地完善代码,可以使用块名称和块文件名而不是核心/模板,因为核心/模板使用核心资源。

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页面链接。

<?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页面

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. 我正在从bootstrap创建一个模态,我需要使用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而且知之甚少。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM