Magento 2: How to call any template block from phtml file?

In Magento 1.x, you could call/print any module’s template block in any other template (phtml) file with the following code: echo $this->getLayout() ->createBlock('newmodule/newblock') ->setTemplate('newmodule/newblock.phtml') ->toHtml(); In Magento 2.x, it’s slightly different. Below is the code to call/print a custom template block in another template file in Magento 2. Suppose, you want to call a template … Read more

Magento 2: How to call CMS Static Block from template (phtml) file?

In Magento 1.x, you could call/print the CMS Static Block in template file with the following code: echo $this->getLayout() ->createBlock('cms/block') ->setBlockId('your_block_identifier') ->toHTML(); In Magento 2.x, it’s quite similar. Below are the sample codes to show/call template (.phtml) files in Magento 2. Call CMS Static Block in any template (.phtml) file echo $this->getLayout() ->createBlock('Magento\Cms\Block\Block') ->setBlockId('your_block_identifier') ->toHtml(); … Read more

Magento: Incorrect template design for login and register page due to Persistent Shopping Cart

Problem: I am using Magento 1.6 and my login and register page design has problem. It is not taking the template path from my custom theme. Instead, it is taking the template path from base persistent folder. For example, the login template path is taken from frontend/base/default/template/persistent/customer/form/login.phtml instead of frontend/default/MY_THEME/template/customer/form/login.phtml It’s strange how this persistent … Read more

Magento: How to get controller, module, action and router name?

You can easily get controller name, action name, router name and module name in any template file or class file. IN TEMPLATE FILES $this->getRequest() can be used in template (phtml) files. Here is the code: /** * get Controller name */ $this->getRequest()->getControllerName(); /** * get Action name, i.e. the function inside the controller */ $this->getRequest()->getActionName(); … Read more

Magento: How to call static block from template (.phtml) file?

You can easily call any static block from template (phtml) file. At first, you have to create a static block. Let us suppose, you created a static block with the identifier cool_items. Now, you can call the static block from any phtml file with the help of following code: echo $this->getLayout() ->createBlock('cms/block') ->setBlockId('cool_items') ->toHTML(); Thanks.

Smarty: Selection list using foreach and section loop

In this article, I will be explaining about foreach and section loop used in Smarty. I will be using these loops for creating a selection list. We can create selection list from a custom Smarty function html_options. <select name="user"> {html_options values=$id output=$names selected="4"} </select> Instead of html_options, we can also use loops to create the … Read more

Smarty: Include header and footer template

In previous article, I had written about installing and using Smarty. In this article, I will be showing how you can include header and footer in Smarty. index.php assigns contents and calls the template file index.tpl <?php require_once('classes/ConnectSmarty.class.php'); // create an object of the class included above $smarty = new ConnectSmarty; // assign content $smarty->assign('name','Mukesh … Read more

Smarty Template Engine: How to install and use? [BEGINNER’S GUIDE]

In this article, I will be introducing how to use Smarty Template engine. This is a beginner tutorial. First of all, you need to download Smarty from http://www.smarty.net/download. You can follow a quickstart guide from here as well: http://www.smarty.net/quick_install. My approach of coding is a bit different than the quickstart guide present on smarty website. … Read more