I have a theme I purchased from ThemeForest, but they are not being helpful (they don't understand english much!)

My question in terms of loading Classes are based on the following:

/** @var $block \Magento\Catalog\Block\Product\Image */
/** @var $escaper \Magento\Framework\Escaper */
/** @var \Magento\Framework\View\Helper\SecureHtmlRenderer $secureRenderer */
 * Enable lazy loading for images with borders and if variable enable_lazy_loading_for_images_w>
 * is enabled in view.xml. Otherwise small size images without borders may be distorted. So max>
 * to prevent stretching and lazy loading does not work.
$borders = (bool)$block->getVar('product_image_white_borders', 'Magento_Catalog');

The 'commented' @var syntax as inside there, is Magento 2 supposed to 'autoload' those class definitions/files?

This is the error:

Exception #0 (Exception): Notice: Undefined variable: escaper in 
/var/www/html/app/design/frontend/Sm/market/Magento_Catalog/templates/product/image_with_borders.phtml on line 35

Line 35:

<img class="<?= $escaper->escapeHtmlAttr($block->getClass()) ?>

I am trying to figure out why they used 'commented @var entries', and why Escaper is undefined.
Interestingly, $block as image does not fail a few lines upwards: (line 15)

$block->getVar('product_image_white_borders', 'Magento_Catalog');`

It feels more like Magento\Framework is not loaded, I see no module Magento_Framework for instance. NOTE: I assume Framework is loaded differently by Magento 2, but I can't verify if it working or not!

This must be something not loaded, because they use @var definitions in alot of their templates.

Extra info

I have already run

bin/magento setup:upgrade && \
bin/magento setup:static-content:deploy -f en_GB en_US && bin/magento setup:di:compile

Please assist, Thanks!

2 Answers 2


It looks like the theme you bought is for magento 2.4
You can see more details in this question and answer: Sanitizing HTML output in templates in 2.4 and in the official documentation https://devdocs.magento.com/guides/v2.4/extension-dev-guide/xss-protection.html

If you want to make it work for 2.3, you can replace in all the templates $escaper->... with $block->....

  • They did update it for Magento 2.4, but claimed that it works with Magento 2.3.5. Thanks this makes sense, now how do I explain this to them!!!! Sep 14, 2020 at 14:35
  • However, there is an Magento\Framework\Escaper.php file in my Magento 2.3.5 installation? Sep 14, 2020 at 14:36
  • 1
    Tell them it doesn't work with 2.3 and also show them the differences between devdocs.magento.com/guides/v2.3/extension-dev-guide/… and devdocs.magento.com/guides/v2.4/extension-dev-guide/…
    – Marius
    Sep 14, 2020 at 14:37
  • 1
    @CvRChameleon. Yes, there is an escaper file and class. the class is not new. it has been there for a while. it is just not available in the templates for versions before 2.4. Read the question and the answer in the first link for more info
    – Marius
    Sep 14, 2020 at 14:38
  • Thanks for the quick clarification! I will tell them that it does not work. Luckily I have the older version downloaded as well - pre2.4 downloaded (never used it). Sep 14, 2020 at 14:40

Purchased themes for M2 generally aren't a good idea, in my opinion.

The comments don't autoload anything. They are only there to signal your IDE which classes the objects have, so the IDE can suggest methods you can use when programming.

The error simply means that the theme has a bug.

To solve it in this particular case, you may be able to replace $escaper with $block. It should work.

  • Interesting that you say they don't autoload :( . I wonder why they did that, it's done in several files! Then I assume $block is then populated upwards in the call stack trace? As in populated in some other PHP File? So I need to initialize the Magento\Framework\Escaper $escaper file myself? Sep 14, 2020 at 14:34
  • 1
    Yes, $block is generally available in template files and populated a few calls above that. I explained why they did that: it’s for the IDE Sep 14, 2020 at 14:40
  • Thanks :) Marius pointed out is a difference between Magento2.3 and Magento 2.4, however when I purchased the theme they claimed this version works with M2.3, M2.4. I am glad that I do not bother upgrading to 2.4 yet - its vastly different. Sep 14, 2020 at 14:45
  • Typically, Marius knows more about things than me :) So I would assume he is right. Their claim is just another reason I wouldn’t buy any theme for M2 Sep 14, 2020 at 14:55
  • Haha :) Yes I actually tried to make sure to find a 2.3.5 compatible theme, time is restricted when I have to handle everything - docker, server configuration, data migration from M1 (NIGHTMARE!!!!) etc Sep 14, 2020 at 14:59

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.