2012-09-17

Template and Block Path Hints by Configuration

Magento Template and Block Path Hints

So you are building a new Magento theme or customizing an existing one? Your customer loves "that one", but it should look a bit like "this one"? Well then, template and Block path hints are your friends.

Magento Template and Block Path Hints

Essentially, template and block path hints are small helpers showing the position of your blocks and templates directly on the page. Using these hints, you can see where which blocks are positioned and which templates are used to render them. This can be a great help, if you want to rearrange the site structure in the process of developing a custom theme, or if you want to change the output of a particular template and need to know which one you have to overwrite.

Enabling Template and Block Path Hints in the Backend

Enabling template and path hints in the backend is straightforward. Go to the admin area, then to System/Configuration, on the left navigation panel go to Developer (under Advanced) and set template path/block path hints to enabled. Note that this option will not be visible in the "default" store scope. You will have to switch at least to the "website" scope to see the option. Otherwise you would see the path hints in the admin area too ... Wait, this is what you wanted? Well, read on.

Enabling Template and Block Path Hints by Configuration

Sometimes it is not convenient to enable and disable path hints in the backend. Suppose you just want to switch them on for a quick check and the magento backend takes ages to load (on my machine with caching switched off it does). Or you are developing something for the backend and want to see where to place it. There is no option for path hints in the backend, so what should you do?

As always with Magento, the solution involves some configuration settings. You have to inject these settings into Magento's configuration and the most easy way to do this (and the only valid one according to Magento's development philosophy), is via the config.xml file of your module. In case you are working on a theme only, you will have to add a dummy module holding the configuration file (see Alan's tutorial for the basic module stucture). In the config.xml of your module, you should add the following section to the <config> (root) node:

<default>
    <dev>
        <debug>
            <template_hints>1</template_hints>
            <template_hints_blocks>1</template_hints_blocks>
        </debug>
    </dev>
</default>

This will enable the showing of template and path hints as a default, i.e., in all stores and in the backend. If you want to disable this, simply set a "0" instead of a "1", or delete the config entry alltogether. This will work, because changing the config does not actually change the underlying DB.

Maybe you'll notice, that in your store views template/block path hints still are not shown. In this case, some setting overwrites the default setting, e.g., you disabled hints on your website scope. This is partly why manipulating the defaults is not good practice. The other part is that you seldomly need to see path hints both in the front- and in the backend while enabling the hints makes the page, ugh, not so pretty. Therefore you should consider setting the configuration only on the store scope.

For example, in order to enable path hints in your admin and in the German store ("de"), you would then use:

<stores>
    <de>
        <dev>
         <debug>
             <template_hints>1</template_hints>
             <template_hints_blocks>1</template_hints_blocks>
         </debug>
        </dev>
    </de>
    <admin>
        <dev>
         <debug>
             <template_hints>1</template_hints>
             <template_hints_blocks>1</template_hints_blocks>
         </debug>
        </dev>
    </admin>
</stores>

2012-09-14

Learning Path to Magento Development

Getting Started with Magento Development

Hey folks, I'd like to welcome y'all to our newly created SAN Magento Dev Blog. The purpose of this blog is to share some of our experiences with the awefulsome Magento ecommerce platform. In this first post, I will describe a basic learning path to becoming a Magento developer. Instead of simply repeating what other people wrote, the post rather references some gems that might really help when starting to learn Magento customization and development.

Why Learn Magento Development?

Magento is a very complex (though fascinating) system and comes with an intimidating code base. However, it has a beautiful take on the MVC architectural pattern and follows GRASP in wide portions, at least as far as this is possible with PHP (ok, PLs are a matter of taste). It does not only favor configuration over convention, it favors configuration over everything. That is, everything in Magento can be configured, which roughly translates into "everything is complicated, but everything is possible". Enough philosophy for now.

As you might already know, or might have guessed, becoming a Magento developer means you will have to face a steep learning curve. It's worth the effort though. Magento allows to satisfy many typical ecommerce requirements out of the box. Its multiverse of extensions does cover even more. However, getting the extensions required by your customers to properly work together is an entirely different story. And nobody likes a store front theme without corporate branding. Plus, there is the occasional process that cannot be mapped, or the requirement that cannot be satisfied, using an off-the-shelf Magento. And ... you could build your own extensions and put them on MagentoConnect (the Magento "App Store"). So the question is:

Where to start?

Unfortunately, there is - to the best of my knowledge - no authoritative resource covering the fundamental Magento development learning path, except maybe Ben's lecture material (linked below). There are some books available, but I did not yet review any of them. Most of them range around 40€ and their reviews draw a rather dark picture, so I decided to spent my time (and money) on other stuff. So if you know some of the available books, please comment and share your experiences. Besides books, there is a vast number of web resources available, including blogs, wiki entries, screencasts etc. Many of them either focussed on a particular topic, as opposed to general understanding, or of mediocre quality. The good news is, there also are some gems out there.

Nuff said, below is a base learning path for all wannabe Magento developers, such as myself. It consists of a sequence of resources I found valuable on my quest to master this beast. You should have a good working knowledge of PHP and object oriented programming (OOP) concepts to make the most out of it. If this is not the case, I recommend you work on these first, otherwise you might be lost along the path. Godspeed.

Learning Path

Set Up Basic *AMP Environment

As always in SW dev, getting your hands dirty as quickly as possible is imperative. So to get started you will need to have a working Magento installation and a development environment at your disposal. I personally use XAMPP on Windows, but any reasonable *AMP stack will suffice. An IDE, e.g., Eclipse (with PDT installed obviously), will help making the actual coding much easier. Additionally, I recommend a build tool to speed up the actual deployment process to a server or your localhost, e.g., Apache Ant or Gradle (ok guilty, I'm comming from a Java background). In order to deploy your Magento modules you will only need to copy some files, so shell scripts or old-school make might be goood enough as well.

Install Magento

The next step, you guessed it, is to install Magento and set it up for development. You might consult the installation videos from the series linked below if you need help there. Basically, the following resources explain the process (create DB, copy Magento, install, configure, enable developer mode):

If you cannot login to your admin panel after installing and get redirected to the login page without any error each time you enter your correctly set up credentials, don't worry: welcome to Magento. This problem exists because of your browser's philosophy and Magento's philosophy, which are not completely aligned. To ease your pain, see this quick fix. Note that this should only happen when running Magento on your machine.

Meet Magento

You should know your way around in both, the store frontend and the admin area. Even more important is that you start grasping the Magento philisophy, the way how you would build a store with Magento. This time simply as a user, we will come to the developer part. If you are new to Magento, Level Up Tuts will help you here:

In my opinion, it is very important to directly apply any concepts learned in the video series. Therefore I didn't recommend installing the sample data. However, you should set up a demo store by working yourself through the examples (e.g., a computer store or a T-shirt store).

Wet Your Feet

Now that you are familiar with basic Magento concepts and their application in real scenarios, you can start down the development road. The first step is the awesome tutorial series written by Alan Storm (thanks Alan, really!!). Fire up your IDE/favorite editor and start hacking:

  1. Introduction to Magento

  2. The Magento Config

  3. Magento Controller Dispatch

  4. Magento Layouts, Blocks and Templates

  5. Magento Models and ORM Basics

  6. Magento Setup Resources

  7. Advanced ORM - Entity Attribute Value

  8. Varien Data Collections

These tutorials build up on each other and you really should follow along implementing each module to make the most out of them. Trust me, it's worth the effort.

Become a Pro

So by now, you have a pretty good feeling about what Magento modules are and you have seen and implemented a couple thereof. There might be still some white spots on your Magento map. Then you should proceed and register at Magento U On-Demand for the "Fundamentals of Magento Development" course held by Ben Marks. Although Ben obviously is not the strongest of all presenters and has his own take on explaining design patterns, he really knows his stuff and will de-mystify all the Magento internals for you. The exercises are really hands on and provide you with an invaluable collection of snippets for various tasks. The course used to be an extensive physical presence course, but is currently available for free.

The course can be found at: Magento U On-Demand

In case this course should be not available for free anymore, or you should be unwilling to register at Magento U On-Demand, there is some guy named NPRMovie on youtube who uploaded the videos. For obvious reasons I cannot link them here. However, I trust you being able to operate the search bar.

Where to Go Now?

So there you are, now a seasoned Magento developer. Well there is not much that I can do for you anymore. Now you will start to benefit from all specific discussions concerning problems you might encounter, e.g., in the Magento forum or on stackoverflow. Additionally, there is the Magento wiki, which holds some interesting articles (sadly enough obfuscated by weird sport event data). Furthermore, there might be a couple of interesting blogs and link collections, ranging from code snippets to full articles: