Using Joomla: Building Powerful and Efficient Web Sites

Using Joomla Using Joomla Ron Severdia and Kenneth Crowder foreword by Louis Landry Beijing • Cambridge • Farnham •...
Author:  Ron Severdia |  Kenneth Crowder

30 downloads 1377 Views 9MB Size Report

This content was uploaded by our users and we assume good faith they have the permission to share this book. If you own the copyright to this book and it is wrongfully on our website, we offer a simple DMCA procedure to remove your content from our site. Start by pressing the button below!

Report copyright / DMCA form



Again, we’re using the title method to get the site name and we’re using a little PHP, not a Joomla function, to determine the current year (based on the web server’s internal clock). The processed result of the previous code is:


In the process of building your template or developing your site, you may need debugging information to help troubleshoot errors. To display debugging information, add the following line to your template, preferably at the bottom: <jdoc:include type="modules" name="debug" />

If you need debugging information, make sure you enable it in the Global Configuration. If debugging isn’t turned on in the Global Configuration, this JDOC statement will be ignored. See Chapter 4 for details on how to do this.

That’s the structure of our barebones template and how each part works. Your template will be different and you can move things around to suit your needs and site design.

JDOC Statements We saw a few JDOC statements in the previous section, so now let’s clarify what they do. They are basically placeholders in your template for specific types of information. Here are the JDOC types and an example of each: head <jdoc:include type="head" />

As shown in the previous section, this type includes the standard Joomla header information, including site name, metadata, and CSS or JavaScript links. There should be only one in your template. message <jdoc:include type="message" />

This displays important messages to your users. It may be a component failure or just a user who has failed to log in. It gives a more specific error message about the problem and possibly how to resolve it. There should be only one in your template. component <jdoc:include type="component" />

As previously described, the component type displays your main content and component information. It usually lives in the center of your template and should never be duplicated. Anatomy of a Template File | 165

module <jdoc:include type="module” name="left" />

This displays a module in the position named. modules <jdoc:include type="modules” name="left" />

This displays a module in the position named but allows for individual module chrome within a single position. installation <jdoc:include type="installation" />

This is used by the Extension Manager when installing a template. JDOC statements require a type, but may optionally also have a style: <jdoc:include type="module” name="left"style="xhtml” />

This is referred to as module chrome and determines the look of a particular module position. Read more about module chrome in “Module Chrome” on page 167.

Template Conditionals Boolean conditionals in your template are used to display information when certain conditions are met. This is a powerful way to customize your template for each section of your website. For example: countModules('right')) : ?>

The first line uses the countModule method to count the number of published modules in the right position. If there are any published modules in that position, the conditional is positive and will display the bottom module with the
tag. If the conditional isn’t met, nothing will be displayed. You can also set multiple conditions for displaying information: countModules('right or left')) : ?>

The first line counts the number of published modules in the right or left positions and displays the bottom module and
tag if it’s positive. You can also use the and operator like in this example: countModules('right and left')) : ?>

This will check to see if both the right and left positions contain a published module and return the bottom module with a
tag if it’s true. 166 | Chapter 11: Templates

Getting creative with these simple conditionals will give you layout varieties only possible if you create multiple site templates—and they’re much easier to maintain.

Template conditionals can also use arithmetic and comparison operators. See a complete list at http://docs.joomla.org/Template_reference_material.

Module Chrome Module chrome is the way modules are displayed on your site. As we saw in our previous example showing the structure of a template, a module is displayed by adding the following JDOC statement to your template file: <jdoc:include type="modules" name="topmenu" style="-1"/>

The previous statement displays the raw output of any module assigned to the topmenu position in the Module Manager. Following are the chrome options built into Joomla that are determined by the style parameter. You can use either the names or the corresponding numbers: none (-1) Output the raw module content. table (0) Output the module in a table. This is the default option. horz (1) Output the module as a table inside an outer table. xhtml (-2) Output the module in
tags. rounded (-3) Output the module in nested
tags to create rounded corners. outline Output the module with a border and usually used to preview module positions. You can create custom module chrome attributes. Check out the Joomla Documentation wiki at http://docs.joomla.org/Tutorial:More_on_Joomla%21_modules for more information. You can also customize the appearance of modules by using module class suffixes. See Chapter 9 for more information.

Module Chrome | 167

Template Parameters Template parameters (stored in the templateDetails.xml file in the template folder) give users a way to customize a single template in many ways to avoid creating multiple templates. Template creators can also build in many options to help website maintainers avoid writing their own template code. Template parameters also tell the Joomla Extension Manager where to install all the different files and folders when you install a template for the first time. The Extension Manager reads the section between the tags. Following is a sample from the Milkyway templateDetails.xml file: index.php templateDetails.xml template_thumbnail.png params.ini images/arrow.png css/index.html css/template.css html

All the files will be installed and folders created, if needed. You can also avoid naming each file in subfolders and instead install an entire folder. Changing this part of your templateDetails.xml file will have no effect on a template that is already installed. But it might cause a template to fail or to not install fully if incorrectly changed before installing.

In the next example, we’ll use the Milkway template (see Figure 11-15) since it allows you to select a color variation, a background variation, and the width of your template—all without knowing any code!

Figure 11-15. Parameters in the Milkyway template

168 | Chapter 11: Templates

If your params.ini file is unwriteable by Joomla, you’ll need to set the permissions of that file to 755. You can usually do this with an FTP application, but if you need more help, you should contact your hosting provider.

In order to give your users the ability to select parameters, you’ll need to add the parameter information to your template XML file (templateDetails.xml). In Milkyway, the parameters are: <params>

<param name="colorVariation" type="list" default="white" label="Color Variation" description="Color variation to use"> <param name="backgroundVariation" type="list" default="blue" label="Background Variation" description="Background color variation to use"> <param name="widthStyle" type="list" default="fmax" label="Template Width" description="Width style of the template">

Each individual parameter resides within its own set of <param> tags and all of them reside within a parent set of <params> tags so Joomla can find them when you open the template in the Template Manager. The definitions for each parameter are set up as drop-down menu options. For example, the drop-down menu for color variations is: <param name="colorVariation" type="list" default="white" label="Color Variation" description="Color variation to use">

Template Parameters | 169

You can see that the details of the color variation parameter are defined in the first <param> tag: type This is set to show a drop-down menu. Other options might be languages, textarea, usergroup, or even custom parameter types. An extensive list of type options can be found on the Joomla Documentation wiki at http://docs.joomla.org/Tutorial: Template_parameters. default This sets the default value when nothing is selected. label This is the label shown to the user next to the drop-down menu. description This is the label description shown when the user rolls over the label. Then each

Recommend Documents

Using Joomla Using Joomla Ron Severdia and Kenneth Crowder foreword by Louis Landry Beijing • Cambridge • Farnham •...

Using Joomla Using Joomla Ron Severdia and Kenneth Crowder foreword by Louis Landry Beijing • Cambridge • Farnham •...

Building job sites with Joomla! Establish and be in charge of a job site using easily adaptable Joomla! extensions. S...

Building job sites with Joomla! Establish and be in charge of a job site using easily adaptable Joomla! extensions. S...

Building job sites with Joomla! Establish and be in charge of a job site using easily adaptable Joomla! extensions. S...

Building Flash Web Sites ® FOR DUMmIES by Doug Sahlin ‰ Building Flash® Web Sites For Dummies® Published by Wiley ...

Building Flash Web Sites ® FOR DUMmIES by Doug Sahlin ‰ Building Flash Web Sites ® FOR DUMmIES ‰ Building F...

Building Flash Web Sites ® FOR DUMmIES by Doug Sahlin ‰ Building Flash Web Sites ® FOR DUMmIES ‰ Building F...