From fc08af9a69c81f3dd95b5a25d188279f6afd6e21 Mon Sep 17 00:00:00 2001 From: Fabian Schmengler Date: Wed, 23 Jan 2019 12:20:42 +0100 Subject: [PATCH] Add documentation for ThisInTemplateSniff --- Magento/Sniffs/Templates/ThisInTemplateSniff.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 Magento/Sniffs/Templates/ThisInTemplateSniff.md diff --git a/Magento/Sniffs/Templates/ThisInTemplateSniff.md b/Magento/Sniffs/Templates/ThisInTemplateSniff.md new file mode 100644 index 00000000..c214a726 --- /dev/null +++ b/Magento/Sniffs/Templates/ThisInTemplateSniff.md @@ -0,0 +1,13 @@ +# Rule: Do not use `$this` in templates +## Background +In PHTML templates, the current block is available as `$this` and `$block`. The alternative with `$this` has been deprecated and should not be used anymore. + +## Reasoning +`$this` in templates is a legacy from Magento 1. It still works, however this can change any time, should templates and blocks be further decoupled. That's why for new code you should always use `$block` and restrict it to public methods. + +## How it works +Any occurence of `$this` in PHTML files (via file pattern in ruleset.xml) raises a warning. + +## How to fix + +Replace `$this` with `$block`. If you use private or protected methods, make them public. \ No newline at end of file