Magento for Designers: Part 3

Magento for Designers: Part 3

This entry is part 3 of 8 in the Magento for Designers Session
« PreviousNext »

Magento is a stunningly powerful e-commerce platform. In this miniseries, we’ll learn how to get started with the platform, getting to know the terminologies, setting up a store and all related aspects of it and finally learn how to customize it to make it our very own.

In this third part, we’ll focus on the process behind theming Magento: how to install themes, the various concepts you’ll need to understand to create a theme and the general file structure. Excited? Let’s get started!


The Full Series


A Quick Recap

In the last part, we saw how to get your Magento store from installed to ready for deployment including how to set up your products, product categories, taxes, shipping, payment gateways and many more.

Today, we’ll look at the basics of Magento theming. We’ll learn the general idea behind Magento themes, the various terminologies behind it and the basic structure of a theme.


Magento Theme Basics

First up, theming Magento isn’t really as hard as it is purported. It’s a little different from how WordPress or Joomla handles themes, yes, but definitely not difficult. All you need to know is a little know how to start theming like a pro!

To make it brutally simple, a Magento theme is a collection of PHTML, CSS and JS files thrown in together along with XML files to define the structure. A PHTML file consists of regular HTML markup interspersed by PHP code for the functionality. In case, you’re confused, a random block of code looks like so:

<div class="quick-access">
        <?php echo $this->getChildHtml('store_language') ?>
        <p class="welcome-msg"><?php echo $this->getWelcome()?></p>
        <?php echo $this->getChildHtml('topLinks') ?>
</div>

See? It’s really simple once you wrap your head around it. If you’ve worked with creating themes for other systems, great, you’ll pick this up rather quickly. If not, no worries, I’ll walk you through the entire process.

Note that in Magento, the front end and the back end are skinned completely separately. I’m assuming most of you won’t need to skin the backend so I’ll stick to theming the front end alone.


Installing a Theme

Before we start, a number of people DMed me through Twitter/emailed me asking the same question: how to install a theme. I’ll talk about it first.

There are two ways to install a Magento theme:

  • The traditional method where you can just copy the packaged theme to appropriate folder
  • Magento Connect

I’ll talk briefly about both.

Direct Upload/Copy

The first method is the one you’re used to. Download a theme, upload it and done. But you’ll need to know where to upload since this works a little differently than you’d assume.

Themes are packaged differently according to the source but at it’s core, you have 2 folders:

  • app
  • skin

You can just drag these to the root of the installation and let it merge with the existing data.

If by chance, you get the theme packaged as a collection of 3 folders, don’t worry.

The folder containing the PHTML files and the one containing the XML files go into root/app/design/frontend/default/themename while the one containing the CSS files, images and other assets goes into root/skin/frontend/default/themename.

Right now, this is all you need to do. I’ll explain why each part goes to a specific location later below. You can activate your theme now.

Tutorial Image

Navigate to System -> Design and click on Add Design Change.

Tutorial Image

Choose the theme you want, click on save and you’re done.

Magento Connect

Using Magento Connect is easier provided it is available there. Navigate to System ->Magento Connect -> Magento Connect Manager.

After logging in, you’ll be asked to enter the extension key of the theme you want to install. Enter the key and wait for the system to do it’s thing.

Tutorial Image
Tutorial Image

After it has downloaded the necessary files and placed them where they need to be, you can now activate the theme like before.


Magento Design Concepts You Need to Master

When working with Magento, there are a few design related concepts you need to wrap your mind around before you can even start modifying the default theme.

Layouts

Layouts is a clever, new idea in Magento. This system lets you define a page’s, any page’s, structure through properly formed XML tags.

Essentially, you can dictate which section of the page goes where by changing just a few attributes in an XML file. Each view or module gets it’s layout specified by its own XML file.

Layouts in Magento is a big topic and just a few paragraphs here won’t do it justice. Along the way, I’ll cover all the necessary information you need to build your own theme along with a detailed article on layouts to cover all the advanced things you can do with this functionality.

For now, if you’re interested, here is a small snippet to get an idea of what layouts are:

<block type="page/html_notices" name="global_notices" as="global_notices" template="page/html/notices.phtml" />

            <block type="page/html_header" name="header" as="header">
                <block type="page/template_links" name="top.links" as="topLinks"/>
                <block type="page/switch" name="store_language" as="store_language" template="page/switch/languages.phtml"/>
                <block type="core/text_list" name="top.menu" as="topMenu"/>
                <block type="page/html_wrapper" name="top.container" as="topContainer" translate="label">
                    <label>Page Header</label>
                    <action method="setElementClass"><value>top-container</value></action>
                </block>
            </block>

            <block type="page/html_breadcrumbs" name="breadcrumbs" as="breadcrumbs"/>

            <block type="core/text_list" name="left" as="left" translate="label">
                <label>Left Column</label>
            </block>

            <block type="core/messages" name="global_messages" as="global_messages"/>
            <block type="core/messages" name="messages" as="messages"/>

Templates

Templates consist of PHTML files filled with regular HTML markup and PHP code. Similar to WordPress, you use a number of predefined methods to specify the output. Just like with other popular systems, important sections like the header, footer and the sidebar are placed in separate files and pulled in when necessary.

You can have different templates for each view of Magento. For example, you can have different code for a wish list or a checkout page instead of using the same look for the entire site.

Here is a piece of a template for the curious:

<ul class="products-grid">

         <li class="item">
              <p class="product-image">
                    <a href="<?php echo $_product->getProductUrl() ?>" 
		        title="<?php echo $this->htmlEscape($this->getImageLabel($_product, 'small_image')) ?>">
                        <img src="<?php echo $this->helper('catalog/image')
				         ->init($_product, 'small_image')
				         ->resize(100, 100); ?>" 
		                          width="100" height="100" 
		                          alt="<?php echo $this->htmlEscape($this
				         ->getImageLabel($_product, 'small_image')) ?>" 
		                          title="<?php echo $this->htmlEscape($this
			          	 ->getImageLabel($_product, 'small_image')) ?>" />
                    </a>
              </p>
              <h5 class="product-name">
				<a href="<?php echo $_product->getProductUrl() ?>" 
				title="<?php echo $this->htmlEscape($_product->getName()) ?>">
				<?php echo $this->htmlEscape($_product->getName()) ?></a>
	     </h5>
                <?php echo $this->getReviewsSummaryHtml($_product, 'short') ?>
                <?php echo $this->getPriceHtml($_product, true, '-new') ?>
              
            </li>
        <?php if ($i%$_columnCount==0 || $i==count($_products)): ?>
</ul>

Looks a little messy, I know but strip out the PHP parts and you’ll see how similar it is to other systems.

Skins

Skins are nothing but the CSS files, JavaScript files, images and other assets you’re using in the markup to create your design. Essentially all non PHP assets go here. Fonts for embedding? Some swanky flash demo? A spiffy piece of SVG? All of those fall under this category.

Blocks

Blocks are the integral building blocks of a theme and let you build your theme in a modular fashion.

As part of layouts, this forms the backbone of Magento’s strong templating system. Blocks are essentially sections which you can move around using the XML mentioned above to modify how a page is presented.

Blocks need to reference a relevant template file so that Magento can pull in the required file. A little confused? Here is an example.

<block type="page/html_breadcrumbs" name="breadcrumbs" as="breadcrumbs"/>

We essentially define a new block, which template to load by specifying the type of block and a name. It’s a little different from what we’ve been used to but trust me you’ll get it once you get started developing. Either way, I’ll cover blocks a bit more in detail when we’re building our theme and still more I’ll do a full write up on layouts and blocks down the line so don’t worry if it doesn’t make complete sense now. Just get a general feel for the topics at hand.

Structural Blocks

A structural block defines the basic structure of a page. Think HTML 5 header, footer and aside sections. They were created for the sole purpose of visual demarcation of a design.

Tutorial Image
From the Magento docs

Content Blocks

Content blocks are similar to your regular container/wrapper DIV elements you use in a design. Just like with design, each content block contains a specific functionality or purpose. A menu in your header, a callout in the sidebar, legal clarifications in the footer all go into separate content blocks.

Remember, content blocks are still blocks and map to a specific PHTML file to generate and render its HTML contents.

Tutorial Image
From the Magento docs

Interface

Mentioned finally because from a strict theming perspective of a beginner, this shouldn’t come into play for quite a while.

To be simple, an interface is a named collection of themes you can leverage to define the look of your store.


Important Locations to Keep in Mind Whilst Theming

Just like other powerful software, Magento has a complex file structure. However, for theming along, you can narrow your focus down considerably.

Tutorial ImageTutorial Image

Here are the locations you’ll be working on when creating a theme:

  • root/app/design/frontend/default – The folder of the default interface. Aptly named default, by default. (Heh!)
  • root/app/design/frontend/default/Cirrus – The folder for the theme we will be building. I’ve named our theme, Cirrus
  • root/skin/frontend/default – The folder of the default interface.
  • root/skin/frontend/default/Cirrus – The folder where all the assets for our theme will be placed.

A Theme’s Directory Structure

Magento requires that your executable PHP content be placed seperately from your static assets which is why you have a separate skin directory on your root. While this may seem counter-productive at first, once you’ve slightly adapted your workflow, you’ll realize that this move increases the general security of your installation..

Nevertheless, a theme is typically split into the following parts.

  • Layouts – root/app/design/frontend/default/Cirrus/layouts
  • Templates – root/app/design/frontend/default/Cirrus/templates
  • Skins – root/skin/frontend/default/Cirrus

The [Second to] Last Word

And we are done! We looked at the basic concepts behind theming Magento and managing themes. Hopefully this has been useful to you and you found it interesting. Since this is a rather new topic for a lot of readers I’ll be closely watching the comments section so chime in there if you’re having any doubts.

Questions? Nice things to say? Criticisms? Hit the comments section and leave me a comment. Happy coding!


What We’ll Build in the Upcoming Parts

So far, we’ve been dealing strictly theoretically with the platform. A necessity considering Magento’s size and scope. But now that we have all the basics nailed down we can move on to the fun part.

Remember how when creating a skin for a CMS/generic system you always start from a skeleton and build outwards? Like Kubrick for WordPress? If you thought we were going to take one and start building a theme out of it, you thought wrong. No, sir. We’re going to build a custom, bare bones skin similar to the Blank skin completely from scratch. A skin you can use yourselves as a base for your own skin.

All this and more in the upcoming parts. Stay tuned!


The Full Series


Purchase Magento Themes from ThemeForest

ThemeForest

Did you know that your friendly neighborhood ThemeForest sells premium quality Magento themes? Whether you’re a skilled Magento developer looking to start profiting from your efforts, or a buyer, hoping to build your first eCommerce store, we’ve got you covered!

Siddharth is Siddharth on Codecanyon
Tags: magento
Note: Want to add some source code? Type <pre><code> before it and </code></pre> after it. Find out more
  • http://www.ceatriks.com/ Reggie

    Great Tutorial. I will be patiently waiting for the next part :-)

  • DW03

    Thanks for tutorial )) I think magento is best platform for eCommerce . And yours tutorials are useful ))

  • Myke

    Can’t wait to see the execution of this bare bones skin. The Blank skin in Magento Connect can be a pain to work with, too many tables, etc.

  • http://twitter.com/xrommelx xRommelx

    this is very useful for me in this momento thank you TUTS+

  • http://www.expertscoder.com sam smih

    I thing they done really good for this tuts . this is help us a lot for development Magneto

  • http://www.geekfill.com Aayush

    This is great! I love that you are focusing on Magento more now…Great Tutorial…

  • http://www.psdtomagento.org Magento Services

    I liked this tutorial. Straight to the point.

  • http://generonquillo.com Gene

    Finally, a magento tutorial series. I have developed a few skins for magento but never started from scratch. The template folders are just too many.

  • Dave Kennedy

    Hat is properly munched. Now we are getting to the real good stuff.

    • http://www.ssiddharth.com Siddharth
      Author

      I laughed hard. I actually thought I’d leave a comment in the earlier thread asking you to eat your hat but you, good sir, are a man of your words. You have my respect. :)

  • http://www.pingvps.com Steve

    Excellent, the first parts of this series didn’t mean much to me as our experience is way past the basics with Magento, but the theme tuts are exactly what we’re looking for.

    Had a quick read and found it very useful, going to have a good long read of this section and then attempt to play around with a theme.

    Are there any good books (or ebooks) available for Magento theming?
    The official Magento guide is pretty useless as far as theme design goes.

    • Mike

      I too am looking for some in-depth reading material. There seem to be a bunch of basic regurgitated tutorials and information about basic css and images.

      I’ve found this system to incredibly time consuming to build for. I’m running 6 eCommerce clients, and I was looking for something new to offer; Magento seemed to the be the right fit. But getting up to speed has been a nightmare!

  • http://livelyworks.net/ LivelyWorks

    Thanks for such a great tutorial. :)

  • http://psdho.me PSDhome – Everyday free PHOTOSHOP files

    Really good tutorial. Thanks.

  • Suzyq

    OMG! SO looking forward to your tutorials. Cant wait. The documentation on theming for magento is generally very crap. Especially for the latest 1.4 version (which has seemed to have changed its structure from the previous versions) Thanks in advance.

    P.S. When can we expect the next installment?

  • http://nineteeneightyfour.info Martyn

    What I just read took me 3-4 months to figure on my own, magentos documentation aint great.

    I Look forward to the next part, Ive been learning and developing with magento for a few months but look forward to see you create a theme from scratch.

  • http://www.dpitmedia.com Dave

    Awesome stuff so far. Looking forward to some more in-depth explanations of things like using blocks , layouts, and templates.

    • http://www.ssiddharth.com Siddharth
      Author

      I will elaborate on them when we’re building our theme. Right now, I wanted to give a simpler explanation so the reader is comfortable when I explain further.

      Thanks for reading.

  • Evan

    Most excellent! Been stuck modding osC for a bit too long.

    If I were to get a generic web host for Magento, would it have to be VPS or Dedicated to run well? (My dream is to hook in Amazon mySQL RDMS and EC2 to create a scalable e-commerce site. A guy can dream right?)

    Would love to hear any thoughts..

    • http://www.ssiddharth.com Siddharth
      Author

      I’ll be brutally honest here:

      Magento is slow. It’s enterprise level software. It’s a beast with the number of classes in the high five figures.

      Running it on shared hosting may be ok for very small to small level sites. Once you leave that range, getting at least a VPS is recommended.

      • Evan

        Thanks Siddharth. Your tutorials are some of my favorite on here.

        Also, ;ittle did I know, Magento wrote a white paper that I’m reading through on performance issues:
        http://www.magentocommerce.com/whitepaper

        E-Commerce is fun :D

  • http://www.newoutlet.com/ Wai Phyo Han

    Great magento tuts series! Very useful for me. thanks!

  • http://www.tenaxtechnologies.com java developer

    Another great tutorial.
    Thanks.

  • http://www.jordanwalker.net Jordan Walker

    Great information on Magento Design.

  • http://www.pokerbanda.com Andrew

    You are doing good job on these tutorials.
    Looking forward to see some advanced stuff, maybe something about mass imports etc.

    Thanks man.

  • Zoran

    With all due respect to the author, but this link http://www.magentocommerce.com/design_guide is much better starting point for Magento designers than this tutorial. I wonder how many series there will be, cause if you explain everything than this will be very long, especially when it comes to layouts and how layouts work, about layout handles, updates, adding, removing blocks via xml, assigning templates for structural or content block, changing the whole layout of the page, adding your own layout along with the Magento’s four layouts, using Blocks in templates, making modules, using Models in Blocks because Blocks are used in templates, changing layouts/templates through controllers, creating static pages, adding static blocks,…etc etc… Magento is not like any other platforms, it’s a beast of a framework and it cannot be explained with ease, cause there are so many things connected, making Magento very hard to understand and learn. I hope lots of these things will be covered soon. :) Thanks!

    • http://www.ssiddharth.com Siddharth
      Author

      I think I understand the complexity of the system which is why I said we’ll be building a simple skin and learn all the necessary skills along the way. Some of the topics you mentioned won’t be part of the series and I’ll probably write them as standalone articles in the future.

      Thanks for reading. :)

  • http://www.rachilli.co.uk Rachel

    I posted this comment on the previous post but nobody’s answered – can anyone help me at all?

    “I’ve set up the product categories and a new product exactly as it was described in the above tutorial…but when I search for my product, I can’t find it anywhere! Is there anything obvious I’m doing wrong? The category and product are both enabled but I can’t seem to find why it won’t display the product.”

    I really don’t understadn why the products aren’t being set up properly/why I can’t view them. Also I’m running 1.4.0.1 but seem to have a different layout to the one shown? I have 13 tabs to set up products rather than 11.

    • http://hov.silwing.dk Silwing

      In case anyone else has this problem you should check if you have set the item “In Stock” on the Stock-tab. Of some odd reason it is defaulted to “Not in stock” even if the amount of items is greater than 0.

  • http://www.neerajkumar.name/ Neeraj Kumar

    Can’t wait for the next part

  • Dasani

    Hello there.
    Did someone have the same problem as I did? I connected my local installation to Magento Connect, and download the Blue Skin, and after that I can’t get back to admin panel of magento installation :) How comes?
    And what I have now, every time I want to get to front of my store (http://localhost/magento/) it’s transferring me to http://localhost/magento/downloader/
    I don’t know what to do for now :)

    • http://www.jeronone.com Sandeep Goyal

      @Dasani..
      Go to root/var/cache. Make the cache folder empty. Close the browser window and open it again. It should work.

  • Eloy Rubio

    Hi Dasani,

    I had the same problem as you say.

    Try this:

    http://localhost:80/magento/admin

    It worked for me ;)

  • http://www.measureddesigns.com/ Measured Designs

    A great tutorial series, I’m glad to see that Magento is finally getting some good documentation as much of the info out there is on the brief side or pre 1.4.

    Some info on widget use and setting up latest product slideshows would be fantastic.

  • http://www.johnsthomas.com John

    When do we get more? Can’t wait for the rest. :-)

  • HammHetfield

    Thanks for this series, I’m sure it’s gonna be a great one, like CI’s series !

    I’m actually trying to learn Magento’s Theming, with other tutorials but I can’t understand the process between… I-don’t-know-what and the rendering of the page, I don’t understand what does Magento read first, and next, etc etc… It’s killing me, I never know where to start, etc etc. I hope that your serie will still be really clear about all the points that a beginner needs to know and understand !

    Thanks again :) (and hurry up, I’m addict)

  • http://www.eyebridge.in Eyebridge

    Hi guys, The developers in our company are working in Magento. Its really great. If anyone needs help you can drop mail @ Eyebridge.in

  • Sean D

    I’ve been waiting for something like this to come along. I am new to Magento and I am having difficulty wrapping my head around the fact that the navigation is so different. I really want to create links (and drop downs) to my static CMS pages in the nav bar along with my product categories. I really hope you are going to cover this.

  • http://www.geekfill.com Aayush

    more of the series…? we’re waiting…

  • http://www.code-pal.com Rakesh Menon

    Thank you :)

  • Adrian

    When can we expect the next tutorial? I really like them. Thank you

  • http://www.tasbelanja.com sandika

    wow… thanks a lot for this tutorial. This is what i looking for. =)

  • Yatin

    Hey,

    Nice tutorial :)

    I have found another site regarding the tutorial,

    http://phpschools.freehostia.com

  • Patrick

    I would be interested to know how to the (packaged) “modern” theme can be used as the base / fallback theme without creating an installation that can’t be upgraded (i.e. cloning all files in modern to your own package)

    It seems to me that the process outlined at http://www.magentocommerce.com/knowledge-base/entry/magentos-theme-hierarchy (ultimately) only allows themes to fall back to app/design/frontend/base/default. If so (and as a workaround) how can you configure Magento such that “app/design/frontend/base/default” is the modern theme ?

    Many sites like to base their look and feel off the “modern” theme. Is there should be a way to derive/override themes (similiar to C++ classes, e.g.) and fallback to one of the packaged themes ?

    Regards,

    Patrick

  • http://zoosper.com/ damu

    The tut rocks as always… Please continue with advance topics.

  • Umar

    Hi, Nice tutorials
    I have a question that can a theme ( made by following this tutorials ) be applied to Magento 1.4?
    or is this for magento 1.3?

  • http://www.google.com simranjit singh

    hi dear can u write any tutorial about os commerce its like magento but little bit different

  • slides

    hi,,

    Thanks for the tutorial,
    can you explain further the attribute “type” and it’s value ?

    in your tutorial the value of type attribute is something like this:
    <block type="page/html_header"
    <block type="page/template_links

    how do you know?what is your basis?

  • http://psdtomagento.net tuba

    Very nice tutorial for magento theme developers, thanks!

  • http://www.sqlstudy.com/ Magento开发

    Great post, exactly what i was looking for… Thanks!

  • anu

    very helpful to designer to understand mangento ..

  • http://r1project.co.cc Mel

    Great tutorial!

  • http://www.jonice.com Jonice

    Thanks for the clear article! on the way create new theme for magento. :D

  • http://nourl soumyadeep bhattacharjee

    Hello Mr.Siddharth,
    I am new in magento and this kind of help from you is very helpful to new comers like me,I want to tell you one thing that thank you very much.

  • Chris

    Thanks a lot Siddarth

    This tutorial is really helpful!

  • raja

    thank you very much Sidarth, its really helpful.

  • Muneeb

    i’m still waiting for the next part of the themening series

  • Ava foll

    I just like the post shared and it would be worth when we see people giving their valuable feedback which motivates the author.Thanks for sharing. http://www.samiflabs.com