PART 1.2.3 – Templates

Overriding and customisations

There is two places where you can find templates. Some of template use phtml files, some of them use knockout.js.


To prevent XSS issues, Magento recommends the following rules of escapingHTML content in templates:

Escape data using the following methods:

  • $block->escapeHtml()
  • $block->escapeQuote()
  • $block->escapeUrl()
  • $block->escapeXssInUrl()

If a method indicates that the contents are escaped, do not escape: getTitleHtml(), getHtmlTitle() (the title is ready for the HTML output)



<?php echo $block->getTitleHtml() ?>


<?php echo $block->getHtmlTitle() ?>


<?php echo $block->escapeHtml($block->getTitle()) ?>


<h1><?php echo (int)$block->getId() ?></h1>


<?php echo count($var); ?>


<?php echo ‘some text’ ?>


<?php echo “some text” ?>


<a href=”<?php echo $block->escapeXssInUrl($block->getUrl()) ?>”>


<?php echo $block->getAnchorTextHtml() ?>



Magento 2.2

The upcoming release of Magento 2.2 will deprecate these functions.Please check back on this page ( after the 2.2 release for updated documentation on new escape functions.


Magento 2’s variables used in template shouldn’t have underscore “_” in the name what is a different comparing to Magento 1.

Magento 1

Magento 2



Exercise 6.0

Remove product name from items on category page.