Want to call one phtml file in another phtml file with anchor tag

I am using Magento.

I want to display and call one phtml file as a link in another phtml file ...

I have a new.phtml file on my home page. On this I put one link CHECK ALL, which displays all new products as a category. It looks like a category page. To do this, I create another phtml file called newproductpage.phtml , which has the same new.phtml code. Now I am trying to call this newproductpage.phtml file CHECK ALL because I am writing this code ....

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

But its not working ....

Thnx ..

+4
source share
6 answers

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

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

Use the code below to render your phtml file in another phtml file.

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

For a more precise definition of the code, you can use the block name and the file name of the block instead of the kernel / template, because the main / template uses the main resources.

+4
source

You cannot directly call one phtml file to another phtml file.

But there are two ways to call your phtml file, or create one controller, and create one action and call the action from your anchor tag, or create one cms page that calls your phtml file.

if you create one module, so in your layout file 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 the content area of ​​the cms page

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

and in the anchor tag, provide a link to the cms page.

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

You can also check the link.

Show .phtml page on another .phtml page

+1
source

I believe that you and I want to do the same. I am creating a modal from bootstrap and I need to call partial using href attr.

So far, I think it is possible by creating a page in CMS and then using something like this:

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

But to be honest, I'm just starting out with Magento and know very little.

0
source

you can use an iframe to do this and load this other page content with an AJAX call

-8
source

Source: https://habr.com/ru/post/906302/


All Articles