Magento Expert Forum - Improve your Magento experience

Results 1 to 2 of 2

Using $this in magento programming

  1. #1
    Moderator speed2x's Avatar
    Join Date
    Mar 2013
    Hollywood, Florida, United States
    Thanked 7 Times in 6 Posts

    Default Using $this in magento programming

    The infamous $this found in Magento templates is a concept that I’ve found 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 (We actually are! See Mage_Core_Block_Template::fetchView).

    Blocks are PHP classes that are designed as a place to put all of your business logic, instead of your templates. Blocks are normally reusable classes. A great example of the reusability of certain classes is the Mage_Core_Block_Template and Mage_Page_Block_Html_Pager classes. 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 provides generic methods for paginating collections, such as isLastPage().

    If you’re 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.

    View more threads in the same category:

  2. #2
    New member
    Join Date
    Mar 2016
    Walnut,CA USA
    Thanked 0 Times in 0 Posts


    Magento is an Ecommerce Platform Created On Open Source Technology, which provides online merchants with an exceptional flexibility and control over the content, look and functionality of their e-commerce store.

Tags for this Thread


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts