Chapter 5. Your Template in Action

Now that we’ve got our template designed, styled, and looking great, we just have one last thing to do. It’s time to share your template with your client, friends, or the rest of the world.

We’ll discuss how to set up your templateDetails.xml file and we’ll go over what each part of that file does in detail. We’ll then discuss compressing your template files into the ZIP file format and running some test installations of your template package in the Joomla! Administration Panel. We’ll even go over a few troubleshooting options if, for some reason, your template doesn’t install correctly.

A Picture’s Worth

Before we begin wrapping up our template package, we’ll need one more thing: the template’s preview thumbnail. Take a screenshot of your final layout and save it to be about 200 to 205 pixels wide. Place your image in your template’s root directory structure so that it’s next to your templateDetails.xml file. The thumbnail file must be named template_thumbnail.png. Later, we’ll assign this image to tag the templateDetails.xml file.

If all goes well, when we test install our package, our Joomla! Administration Panel should give us a rollover sample of the template design.

A Picture’s Worth

Figure 5.1 My_Nature_Web template preview.

Easy XML

The first thing we need to do so as to pull our template together is to put all the required file information into our templateDetails.xml file. You can leave behind any preconceptions that XML documents are incredibly complicated things that only the super geeky, non-visual designers traverse. You’ll recall we already looked at this file in Chapter 3 and it wasn’t scary at all.

This XML document is extremely simple, but nonetheless you’ll want to be careful with the syntax in it. An accidentally deleted > bracket or forgetting a closing </nodeName> tag will break the XML file, and your final ZIP file will not upload and install properly. With a little understanding of what each tag does and some attention to detail, you shouldn’t have any problems.

Most good HTML editors like Dreamweaver will open up your XML document and keep it intact and valid. You can use an XML document editor like Altova’s XML Spy http://www.altova.com/, but this software is prohibitively expensive, especially if you don’t intend on become an XML architect. If you’re editing on a Windows PC, then XML Marker from SymbolClick http://symbolclick.com/ is a good free editor. An XML editor will usually let you view the XML’s structure in a grid format, and let you edit node content and attributes easily without disturbing the surrounding syntax.

Easy XML

Figure 5.2 templateDetails.xml in XML Marker

There are also component extensions for Joomla! that you can use to generate your templateDetails.xml file. Yes, this is a bit confusing and sounds like the horse before the cart. As you can see we’ve been developing our Joomla! templates by hand—from scratch by uploading a base template folder and modifying the files. The following extensions will allow you to generate your templateDetails.xml file from Joomla!, once you’ve completed your template design. I have not used these extensions myself, but if you’re really uncomfortable working with XML these might be a good option for you.

There’s the Template XML generator component: http://extensions.joomla.org/component/option,com_mtree/task,viewlink/link_id,355/Itemid,35/

And the Joomla! TemplateDetails.xml Generator: http://extensions.joomla.org/component/option,com_mtree/task,viewlink/link_id,585/Itemid,35/

Getting to Know Your XML

Whether or not you’ll be working with an XML generator component, your HTML editor, or an XML editor, it’s good to understand what the templateDetails.xml file contains and what each part of it is meant to do. If there are any issues with your package, knowing what each part does will greatly ease troubleshooting and aid in fixing your installation. If any piece of your template is not added to this file in the appropriate tags, your package will produce errors upon installation.

Here’s our templateDetails.xml file as it stands as of Chapter 3:

<?xml version="1.0" encoding="iso-8859-1"?>
<mosinstall type="template" version="1.0.0">
    <name>my_nature_design</name>
    <creationDate>12/22/06</creationDate>
    <author>my name</author>
    <copyright>GNU/GPL</copyright>
    <authorEmail>[email protected]</authorEmail>
    <authorUrl>http://www.mysite.com</authorUrl>
    <version>2.2</version>
    <description>A simple and stylish template. Based on Rhuk's
                                   Solarflare II design</description>
    <files>
        <filename>index.php</filename>
        <filename>template_thumbnail.png</filename>
    </files>
    <images>
        <filename>images/advertisement.png</filename>
        <filename>images/arrow.png</filename>
            <filename>images/button_bg.png</filename>
        <filename>images/contenthead.png</filename>
        <filename>images/indent1.png</filename>
        <filename>images/indent2.png</filename>
        <filename>images/indent3.png</filename>
        <filename>images/indent4.png</filename>
        <filename>images/header_short.jpg</filename>
        <filename>images/menu_bg.png</filename>
        <filename>images/powered_by.png</filename>
        <filename>images/spacer.png</filename>
        <filename>images/subhead_bg.png</filename>
        <filename>images/title_back.png</filename>
    </images>
    <css>
        <filename>css/template_css.css</filename>
    </css>
</mosinstall>

Now, all we really changed was the name of the template so that we could differentiate it from the original Rhuk template in our Joomla! Administration Panel. The rest of the information in this XML file is still Rhuk’s. Let’s learn what each tag does.

<?xml version="1.0" encoding="iso-8859-1"?>

This is XML’s DOCTYPE, and you’re pretty much going to leave it alone. We’re pretty sure that our template is only going to be used primarily with computers using Western languages, so we’ll leave the encoding as iso-8859-1. If you’re hoping for a wide distribution of your template on machines using other languages, it might be better to set this to UTF-8.

<mosinstall type="template" version="1.0.0">

You’ll notice that everything else is tucked into this <mosinstall... tag. Don’t forget to add the closing </mosinstall> tag at the very end of your file!

The attributes type="template" and version="1.0.0" tell the installer that we are installing a template and also what version of Joomla! it’s optimally designed for. If you’re using a development version of Joomla! that’s greater than 1.0.0 (probably 1.0.8 or 1.0.12 as at the time of writing) you should enter those numbers into the version attribute. We’ll change the version number 1.0.8 for our templateDetails.xml file.

<name>my_nature_design</name>

As mentioned, we added our own template name in Chapter 3 when we set up our development area. This tag defines the name of your template. This name is also used to generate the directory within the template directory. As a result, you cannot use characters that the file system cannot handle, like spaces or special symbols. You’ll notice in Chapter 3 that the file directory that we manually created and copied was named with the same name as the one we entered into the <name> tag. This is required for the template to work properly.

<creationDate>12/22/06</creationDate>

We did update this initially as well. Obviously, you’ll enter the date when your template was created. While the double-digit month/day/year format is standard, there are no real requirements for this tag. You can use any date format you’d like such as a general “May 2007”, the more American “May 30, 2007”, or “2007-05-30”. Just pick something you know your template’s users are going to recognize as a date.

<author>my name</author>

Here you’ll add your name to the template, or perhaps a team, group, or corporate name if a group of you designed the template together.

<copyright>GNU/GPL</copyright>

You’ll place your copyright information in this tag. Rhuk released the solar_flare_ii template under the GNU/GPL license. If you’re not familiar with the GNU/GPL License you can learn more about it at http://www.gnu.org/copyleft/gpl.html. You may wish to do the same with your template. If you do this, it has to be freely distributed, available to all, and changeable by all with no permissions necessary so long as they acknowledge you.

If you’ve created a completely original design that you intend to sell commercially, or just want to be able to grant permission for any other possible use, you’ll need to place specific copyright information and the name of the person or organization that holds the copyright. Something like © 2007 My Name, All Rights Reserved, is generally recognized as legal with or without any formal copyright filing procedures (but you should look up how to best formally copyright your design material).

Our design is leveraged from the Rhuk design for educational purposes, although the GNU/GPL license is more than adequate. Its text is perhaps a bit “softwareish” and “tech-heavy” for our intended audience, so we’re going to redistribute the new nature template under the more general-public-friendly Creative Commons License. We’ll use the CC Labs DHTML License Chooser to assist us in selecting an appropriate license. It can be found at http://labs.creativecommons.org/dhtmllicense/:

Getting to Know Your XML

Figure 5.3 Creative Commons DHTML license chooser

We’ll of course allow sharing of the template, and let others “remix” and derive new works from it (as we remixed Rhuk’s) with proper credit. We will, however, prevent it from being used commercially, and use the Require Share-Alike option. This means that no one can legally take the template package and offer it for sale or use it in such a way that it generates income for them without our permission. If they reuse or redesign the package in any other non-commercial way they’re free to do so, they’re simply required to give us and Rhuk due credit.

Our licensing agreement looks like the following:

my_nature_design by Tessa Blakeley Silver for Packt Publishing, remix inspired by: rhuk_solar_flare_ii, is licensed under a Creative CommonsAttribution-NonCommercial-ShareAlike 2.5 License.

The end result is a license that keeps the spirit of the GNU/GPL license but is much less vague. It tells the user upfront that it allows sharing which is important to us for educational purposes, gives continued credit to the original Rhuk author, prevents commercial distribution without permission, and by requiring share-alike encourages a continued friendly Joomla!-esque atmosphere for open-source collaboration. It also states the version number of the license making it very easy for anyone to look it up and read it in detail.

Additionally, a Licensing Primer for Developers and Designers can be found on the Joomla! forums at http://forum.joomla.org/index.php/topic,22653.0.html.

<authorEmail>[email protected]</authorEmail>
<authorUrl>http://www.mysite.com</authorUrl>

Here, we’ll place a good contact email address for people who might have questions about the template. This is especially important if you’re going to use a straight-up copyright. Make sure people who are seeking permission to use your design can do so, there’s probably cash at stake! While publishing via a Copyright, GPL, or CC license, it’s a good idea to ensure that the email address is best suited for taking technical questions about your template. You are not responsible to be available for “tech-support”, especially under the GNU/GPL or CC license, as everyone’s system and use of Joomla! is unique, so who knows what would go wrong from user to user. However, it would be nice to offer any input or ideas that might help someone else troubleshoot problems that they are having with the template.

Last, in the authorURL tags, place the website address with a page, you feel best encompasses what you want to portray to your target template audience. This is essentially an opportunity to get your URL out there and toot your horn so go on, take advantage of it.

<version>2.2</version>

You may find that your template goes through some revisions before it’s complete, especially if you happen to be working on a team. Perhaps, this is an older template that you’ve just upgraded and overhauled to run a little more smoothly. If you can apply versioning to this template, go ahead and do so. This is the first version of this look for the template so we’ll take it back to version 1.0:

<files>
    <filename>index.php</filename>
    <filename>template_thumbnail.png</filename>
</files>

OK, everything and anything that is not a CSS, or an image that is used in the actual template goes in here. This essentially means your index.php file and the thumbnail preview we made at the beginning of this chapter. You must also place any references to JavaScripts you write or JavaScript libraries used by your template. Path information for your files is relative to the root of your template, hence, your index.php file is just listed. However, if you use JavaScripts that are located inside a folder called js you must indicate that path in the filename <filename>js/moofx.js</filename>.

Be careful that each additional file is listed inside its own <filename>...</filename> tags. We didn’t add any JavaScripts so we’re good to move on.

<images>
    <filename>images/advertisement.png</filename>
    <filename>images/arrow.png</filename>
    <filename>images/button_bg.png</filename>
    <filename>images/contenthead.png</filename>
    <filename>images/indent1.png</filename>
    <filename>images/indent2.png</filename>
    <filename>images/indent3.png</filename>
    <filename>images/indent4.png</filename>
    <filename>images/header_short.jpg</filename>
    <filename>images/menu_bg.png</filename>
    <filename>images/powered_by.png</filename>
    <filename>images/spacer.png</filename>
    <filename>images/subhead_bg.png</filename>
    <filename>images/title_back.png</filename>
</images>

All image files that your template uses will be listed within these tags. Again, each image file must be enclosed with <filename>... </filename> tags. As mentioned, path information for the files is relative to the root of your template. Chances are that you’ve tucked all your template images inside an images folder. Hence, you see the image/filename.png path detailed above. If you didn’t use a directory called images or you’ve broken your images into sub-directories within your main image directory, it’s OK. You must still detail each image with its full path: <filename>images/top-level/filename.png</filename>. We redesigned and overwrote the original Rhuk images for our template, so we can pretty much leave the image calls alone. However, we did rename our main header image, so we’ll replace header_short.jpg with our file name, my_nature_header.jpg.

<css>
    <filename>css/template_css.css</filename>
</css>

Last, you’ll add your style sheet (or style sheets if you are using more than one). Again, the filename is surrounded with <filename>...</filename> tags, and its path must be relative to your template’s root.

Here’s what our final template version looks like:

<?xml version="1.0" encoding="iso-8859-1"?>
<mosinstall type="template" version="1.0.8">
    <name>my_nature_design</name>
    <creationDate>12/22/06</creationDate>
    <author>Tessa Blakeley Silver</author>
    <copyright>my_nature_design by Tessa Blakeley Silver for Packt
                  Publishing, remix inspired by: rhuk_solar_flare_ii,
                  is licensed under a Creative Commons
                  Attribution-NonCommercial-ShareAlike 2.5 License.
                                                       </copyright>
    <authorEmail>[email protected]</authorEmail>
    <authorUrl>http://www.packtpub.com</authorUrl>
    <version>1.0</version>
    <description>A simple and stylish template. Based on Rhuk's
                         Solarflare II design for the
                         Joomla! Template! Design! book</description>
    <files>
        <filename>index.php</filename>
        <filename>template_thumbnail.png</filename>
    </files>
    <images>
        <filename>images/advertisement.png</filename>
        <filename>images/arrow.png</filename>
        <filename>images/button_bg.png</filename>
        <filename>images/contenthead.png</filename>
        <filename>images/indent1.png</filename>
        <filename>images/indent2.png</filename>
        <filename>images/indent3.png</filename>
        <filename>images/indent4.png</filename>
        <filename>images/my_nature_header.jpg</filename>
        <filename>images/menu_bg.png</filename>
        <filename>images/powered_by.png</filename>
        <filename>images/spacer.png</filename>
        <filename>images/subhead_bg.png</filename>
        <filename>images/title_back.png</filename>
    </images>
    <css>
        <filename>css/template_css.css</filename>
    </css>
</mosinstall>

Zip it Up!

We’re now ready to zip up our template files and test an installation of our template package. Zipping is just the file compression type Joomla! prefers. If you’re a Windows PC user, chances are that you’re very familiar with ZIP files. If you’re a Mac user, you’re most likely aware of its equivalent, the .sit or StuffIt file.

Even if you’re working off a server, rather than locally, it’s probably best to download your file directories and zip them up on your local machine. Plus you’ll want to test your install and mostly everyone will be uploading your file off their local machine through Joomla!’s Administration Panel.

No way to zip? You’ll have to take a little tour of the Internet to find the very best ZIP solution for you. There are many free archiving and compression tools that offer the ZIP format. However, we caution you to be careful; we have found some open-source ZIP tools (like a class we used with PHP) that must use an extremely simple or much older set of rules to create ZIP files that Joomla! doesn’t seem to like. However, when we use a relatively new compression tool or the trial versions of good old WinZip and StuffIt, the ZIP files they produce seem to upload and work just fine in our Joomla! Administration Panel.

So let’s start with the obvious. If you don’t have any ZIP compression tools, head over to http://www.stuffit.com/. You’ll find StuffIt software is available for Mac or PC and lets you compress and expand several different types of formats including ZIP. The standard edition is likely to be all you’ll ever need, and while there’s nothing wrong with purchasing good commercial software, you’ll have plenty of time to play with the trial version. We like StuffIt because, although we primarily work with PCs, we do play well with Macs and being able to create and expand .sit files makes us more compatible with our Mac friends. The trial period for the standard software is 15 days but you might find that it lasts longer than that (especially if you’re patient while the “continue trial” button loads). If you’re on a PC, you also have WinZip as an option: http://www.winzip.com/, where again you’re given a trial period that does seem to last longer than the stated 45 days.

WinZip and StuffIt are considered industry-standard software, they’ve been around for a good while, and they are stable products for under $50 (compared to the $700 you might have shelled out for Photoshop or Dreamweaver), so you can’t go too wrong.

Note

Come on, where’s the free Open-Source stuff? If you want truly free compression software and are on a PC, there is 7-zip: http://www.7-zip.org/. We’ve only minimally played around with 7-zip, but it does create and expand ZIP files and can even compress in a new format (called 7z) that gives better compression than standard ZIP files. Unfortunately, the 7z format isn’t compatible with Joomla!, so make sure you’re creating a standard ZIP when you use it.

Each compression utility has its own interface and procedures for creating a standard .zip file. We’ll assume that you have one, or have chosen one from above and have made yourself familiar with it.

Zip it Up!

Figure 5.4 Template’s root directory to zip

You may want to take one last look at your directory and templateDetails.xml file to make sure you’ve placed everything needed for your template structure in the directory. Once you’re sure of this, you can go ahead and compress everything from the root level into a ZIP file.

Uploading to Joomla!

You’re now ready to go to the Joomla! Administration Panel, select Site | Template Manager | Site Templates and click on the New icon. Then click Browse to select your ZIP file, and finally click Upload to begin the installation process into Joomla!.

Hopefully, you will receive a happy Upload Template - Success screen:

Uploading to Joomla!

Figure 5.5 Template Upload Success.

If you instead received an Upload Template – Failed screen, something was wrong with your package. The good news is that the Joomla! template uploader works a bit like W3C’s validator and does a fairly good job of telling you exactly what’s wrong with your package.

It will inform you that it Could not find a Joomla! XML setup file in the package. If you are sure that you have put your templateDetails.xml file in the package, then it’s most likely to be invalid because of typos created when adding your files. Check your XML file carefully to ensure that it has all the proper opening and closing tags, all spelled correctly (remember, just like XHTML, your XML closing tags need “/” backslashes).

If that is not the case, Joomla! will tell you what specifically is wrong with the package.

Uploading to Joomla!

Figure 5.6 Joomla Upload Template Failure

Here in Figure 5.6, you can see that Joomla! has informed us that .../images/title_back.png does not exist!. When we check our templateDetails.xml file, we do find a reference for this image that is not inside our image directory. It is an image we’re not using, but the reference is a hold-over from basing our work off the rhuk template. We’ll delete the reference from our XML file and add it again to our ZIP file, overwriting the old templateDetails.xml file.

When you uploaded the package again, even though it does not show up in the Template Manager panel, it is likely to have got as far as it could into the process of uploading and installing. If it managed to create the initial directory, when you attempt to upload the package again, you’ll get a warning saying that directory already exists.

You must FTP into the templates directory and manually delete the directories and files that were installed by the package. Then, you can go back to the Template Manager, select New, and attempt the process again. Once you’ve got a successful file upload message, you can see the template in the Joomla! Template Manager panel. Assign the template to your installation of Joomla! and make sure that it looks good in all the module and component scenarios you’ve designed it for.

Uploading to Joomla!

Figure 5.7 Joomla! Template installed and appearing in the Template Manager.

With the successful installation and test of your template, you now have an understanding of the entire Joomla! Template development process from conception to packaging.

Summary

In this chapter, we reviewed all the nooks and crannies of the templateDetails.xml file and how to package up your finished template into a working ZIP file that anyone should be able to upload into their own Joomla! installation.

You now know everything there is about getting a Joomla! template design off that coffee shop napkin and into the real world! In the next few chapters, we’ll get down into the real-world nitty-gritty of getting things done quickly with our Template Markup Reference and Cook Book chapters. We’ll cover key design tips and cool how-to’s. You’ll learn how to set up dynamic drop-down menus, best practices for integrating Flash, and more.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.218.127.141