Here’s a simple snippet to pass a PHP variable from a controller ( or whatever magento file ) to a block, using the
When you call a block:
setData() method you’ll be able to access your variable with:
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.
I will be student teaching at Grace International School in Chiang Mai, Thailand!
Sklepy na Magento z Bielska-Białej
Software Development Company in UK
Share Your Idea's
be a pro
Senior Software Engineer
A great WordPress.com site
This website contains useful tips for webdevelopers
ecommerce witterings & adventures in SaaS
Magento Developer in Pakistan
Magento Developer Tutorial Certification training and study kit with questions and answers
eCommerce development company, SynapseIndia has developed thousands of attention-grabbing, quickly loadable & unique shopping stores.
Small & Medium Enterprise high efficiency architecture - forex trading