Skip to content

Commit d539629

Browse files
authored
Merge pull request #15 from schmengler/doc-ThisInTemplate
Add documentation for ThisInTemplateSniff
2 parents c9a10aa + fc08af9 commit d539629

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Rule: Do not use `$this` in templates
2+
## Background
3+
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.
4+
5+
## Reasoning
6+
`$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.
7+
8+
## How it works
9+
Any occurence of `$this` in PHTML files (via file pattern in ruleset.xml) raises a warning.
10+
11+
## How to fix
12+
13+
Replace `$this` with `$block`. If you use private or protected methods, make them public.

0 commit comments

Comments
 (0)