Gantry comes with 65 module positions and the ability to add more can be done with the greatest of ease. Find out more...
In the Gantry framework we use the term Feature to mean a specific bit of functionality. Features are flexible enough that they can be used to perform almost any kind of logic you would need. The base GantryFeature class contains methods that can be implemented to control how your feature functions. Those methods are:
All core features and any custom feature you create, should extend this GantryFeature class. To create a new feature of your own, you would just have to create a new file in your features/ folder that extended the GantryFeature class. It will automatically get picked up by the Gantry framework and be processed. The best way to see what a feature can do for you is to examine a few of the core features.
First let's look at one of the core features called logo.php. As you can imagine the logo.php feature is intended to display a logo. The most important part of a feature is the actual feature PHP file. The core features are located in the YOUR_SITE/components/com_gantry/features/ folder. These should not be touched or changed. If you want to override the behavior of a core feature, simply copy the core feature in your YOUR_SITE/templates/YOUR_TEMPLATE/features folder. Gantry will automatically pick up your version of the file and use it rather than the default version if you have created one with the same name. The other part of a feature and one that is totally optional is the configuration section. As with other parts of Gantry, the configuration is handled in the templateDetails.xml. For the logo feature the section in the templateDetails.xml looks like:
What this means is that in the administrator interface, there is going to be three parameters rendered. One is a toggle element that will control the 'enabled' state. The second is position element that controls the position the feature is rendered in. The third is another toggle to control the auto-resize option for this feature. By exposing these elements in the XML, we allow interaction with the user. If you wanted to add new elements in this XML section, you could and they would be available for you to use in your feature's PHP.
Next, let's look at the PHP for this feature:
As you can see the ONLY method that is used is the render() method. The other methods from the base GantryFeature class are not overridden. That means that the standard methods to get the enabled state, position, etc are being used and are pulling that data from the XML and the admin settings. You can see how custom XML parameters like autosize are easily available and are prefixed by the feature name, so you can just get logo-autosize to get the value for the 'chained' element logo -> autosize.
Next, let's have a look at a custom feature I created for the gantry-framework.org site. We wanted to use MooTools 1.2 for this site, but as we are running in Joomla 1.5, the default version of MooTools is 1.1.12. To change the version of MooTools we created our own custom feature and put it in the features/ folder of our template. The name of the feature is not important, any file found in this directory that extends GantryFeature will automatically be processed.
This feature is a bit of core functionality that doesn't need any user interaction, so we didn't create any section for it in the templateDetails.xml file. All we did was create this moo12.php file:
as you can see we have overridden a few of the base methods. This is because we have no UI we want to hard-code some of the settings. For example, we are forcing the enabled setting to be true. Also we are setting the isInPosition() method to false. This means that this feature will be ignored by the layout rendering process as it doesn't need to be output in a position. Also the isOrderable() method is set to false, as the order of this feature in relation to other features is not important.
There is no render() implementation as this feature is not intended to be rendered in a layout like the logo feature for example, rather all it's functionality is contained in the init() method. In this case the purpose of this features is to find the old reference in the document's _script variable of the default Joomla MooTools 1.12 library, and replace it with a reference to a newer MooTools 1.2.4 version that we have provided in the template.
Have a look through all the default features that come with Gantry to see how we achieved a wide variety of functionality with these features.