Difference of using $this and $block in Magento 2 template

One new thing I found in Magento 2 is the usage of object $block in phtml template to get the block method, instead of using $this as we did in Magento 1.

Let’s say we have this method getFoo() in our block:


then we can call the method from our template with:

and surely will outpout “here is Foo“.

Now, let’s call the method using object  $this:

and… it turns out that its output still the same: “here is Foo“. WHY??

Read More