{"id":4458,"date":"2015-07-31T11:23:49","date_gmt":"2015-07-31T11:23:49","guid":{"rendered":"http:\/\/a1webdesignteam.com\/blog\/?p=4458"},"modified":"2015-07-31T11:23:49","modified_gmt":"2015-07-31T11:23:49","slug":"magento-templates","status":"publish","type":"post","link":"https:\/\/a1webdesignteam.com\/blog\/magento-templates\/","title":{"rendered":"Magento Templates"},"content":{"rendered":"<p>The template system that ships with Magento may seem a little complex at first, but the price we pay in complexity affords us a great deal of flexibility and power, as we\u2019ll discover.<\/p>\n<p>There are three components to the template system:<\/p>\n<p>    PHP template files<br \/>\n    PHP block classes<br \/>\n    XML layout configuration<\/p>\n<p>The template files contain what you\u2019d expect a template system to handle, such as the HTML, JavaScript, and some PHP.<\/p>\n<p>The block classes allow us to move the reusable functionality from the PHP template files into PHP classes, which can be used again on different template files in the future.  As a rule, all template files will have an associated block class.  Block classes are just normal PHP classes, and can be accessed in the template through the $this variable.<\/p>\n<p>Various helper methods, such as getSkinUrl($path) or getUrl($path), are contained in all block classes. These methods are then used in a template file, by calling: $this->getSkinurl(&#8216;images\/logo.png&#8217;), for example.<\/p>\n<p>Along with providing useful methods to the template files, blocks are also used to decide how to render the template file to the user. Each block has a toHtml() method for this purpose. Usually, the toHtml() method will simply parse the template file and output it to the user, but we could override that functionality and return anything we like, such as XML or JSON.<\/p>\n<p>Finally, the XML layout configuration files are the \u201cglue\u201d that pulls together the entire set of template files to be rendered in the browser. In the XML, we can specify what PHP template\/block combinations we\u2019d like to load, and the order that we\u2019d like to display them on the page.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The template system that ships with Magento may seem a little complex at first, but the price we pay in complexity affords us a great deal of flexibility and power, as we\u2019ll discover. There are three components to the template system: PHP template files PHP block classes XML layout configuration The template files contain what [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":4459,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0},"categories":[24],"tags":[51],"_links":{"self":[{"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/posts\/4458"}],"collection":[{"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/comments?post=4458"}],"version-history":[{"count":0,"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/posts\/4458\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/media\/4459"}],"wp:attachment":[{"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/media?parent=4458"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/categories?post=4458"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/tags?post=4458"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}