$this What is it?

When we work at front-end in magento (in templates), we often see $this or $this-> … If you don’t know that,  will you ask a question for it, sometimes? I think this answer is YES

This is problem which baffles beginner Magento developers. Here’s to hoping I can provide a half-decent explanation as to what it is, and where it comes from. The most important point you should take away from this is: all Magento templates have a corresponding block instance. The $this exposed to us is the block instance, as if we were inside a method of the object (See Mage_Core_Block_Template::fetchView).

Blocks in Magento are PHP class that are designed as a place to put all of your business logic, instead of your templates. Blocks are normally reusable class. A great example of the reusability of certain class is the Mage_Core_Block_Template and Mage_Page_Block_Html_Pager class. The core/template block is the foundation of the template system, allowing us the ability to load .phtml files from our themes. The page/html_pager block provide generic methods for paginating collection, such as isLastPage().

If you are ever in any doubt as to which block type the template is using, just call echo get_class($this). Remember, it’s an object.This gives you a great place to start when hunting down methods available to the template.