Magento – Magento 2 html file and phtml file in custom template process

layoutmagento2

As I checked from magento 2 documentation about changing minicart content.

There are two ways :

  1. In this page : http://devdocs.magento.com/guides/v2.0/frontend-dev-guide/themes/theme-inherit.html

We change it by customizing minicart.phml and placing it in:
app/design/frontend/OrangeCo/orange/Magento_Checkout/templates/cart/minicart.phtml

  1. But on the other page :
    http://devdocs.magento.com/guides/v2.0/frontend-dev-guide/templates/template-sample.html

We customise it in content.html and place it in:

app/design/frontend/OrangeCo/orange/Magento_Checkout/web/template/minicart/content.html

So these questions are :

How magento 2 decides when to use html file and phtml file ?

Is this related to 3 mode in Magento 2: Default, Developer and Production ?

Best Answer

Both .phtml and .html files are part of the view layer in Magento 2 difference being phtml files work with Block which according to Magento Docs is a special PHP class that is usually (but not always) connected to a template closely. Blocks usually work with model layer (core Magento) to manipulate data and return results/response to templates (.phtml or .html files). These files are used by layout files in setting up templates for certain blocks and so on.

html files on the other end are solely used to display content on the frontend and javascript libraries such as knockout JS use them accordingly. These files are also used for AJAX content loading.

Related Topic