问题
I'm using Magento.
I want display and call one phtml
file as a link in another phtml
file…
I have the new.phtml
file 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 phtml
file named newproductpage.phtml
which has same code of new.phtml
. Now I try to call this newproductpage.phtml
file @homepage as CHECK ALL link for that I write this code....
<a href="<?php echo $this->getUr('newproductpage.phtml')?>">CHECK ALL</a>
But its not working....
thnx..
回答1:
you call newproductpage.phtml in any phtml file using below code
<?php echo $this->getLayout()->createBlock('core/template')->setTemplate('custom/newproductpage.phtml')->toHtml(); ?>
回答2:
Use the below code for rendering your phtml file in another phtml file.
<?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.
回答3:
You can not call directly one phtml file to another phtml file.
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.
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
{{block type="catalog/product_new" template="custom/newproductpage.phtml"}}
and in anchor tag give cms page link.
回答4:
<?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
回答5:
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.
So far, I think this might be possible by creating a page in the CMS and then using something like this:
<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.
回答6:
you can use iframe for same and load this another page content using AJAX call
来源:https://stackoverflow.com/questions/16691546/want-to-call-one-phtml-file-in-another-phtml-file-using-anchor-tag