I am new to Magento and have been reading all of the answers on how to add PHP to a Magento block or page. Seems that just adding doesn't work. I have seen answers like this

{{block type="core/template" name="my_distributors_block" template="page/distributors.phtml"}}

My challenge is trying to determine where to put the phtml file. I have tried putting it in a php directory off of root directory of the server like:

{{block type="core/template" template="**php/test.phtml**"}}

If I just want to add custom php

  1. What are the exact steps
  2. Is there any documentation that describes what each attribute means, that is what is type, what is name and what is template

Where does phtml files need to reside? Working with Magento 2

1 Answer 1


First of all core/template is not a part of Magento 2.


  • To add any phtml file you need a block or layout file to define a path of your phtml file.

  • type is use to define your Block class which is connected to your phtml file. So you can access block methods in your phtml file.

  • name is used to set a name of your block. It must be unique.

  • template is used to define your phtml file. You have to add template path.

    phtml files are available on module level and on theme level too. you can find those file in app/code/Vendor/Module/view/frontend/templates and app/design/frontend/packageName/themename/Vendor_Module/templates

  • Rakesh, Thank you for getting back. Is there a good document that describes what I need to do in order to run customer php code in a page or block? I have placed the below code in the /app/code/SMCH/ManReg/view/frontend/templates <?php echo "Here I am!!!!"; ?> <h1> <BR> HTML Text </h1> How would I access this from a page or a block?
    – Jim
    Mar 25, 2021 at 21:17
  • I am looking to add php code to page, possibly have it render html tabs that php may print out for display on the page. Is there documentation for this?
    – Jim
    Mar 26, 2021 at 0:12
  • check this link rakeshvarma.com/magento2/create-block-and-phtml-in-magento-2 hope it will helpful. Mar 26, 2021 at 4:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.