In the Gantry framework, we use the term Gizmo to refer to a specific type of functionality. Gizmos are flexible enough that they can be used to perform almost any kind of logic you would need. The base GantryGizmo class contains methods that can be implemented to control how your gizmo functions. Those methods are:
For Joomla, the equivalent tab is called Feature. You can find out more about Joomla gizmos by visiting the Creating a New Feature guide.
boolean(true / false)
string(prefix name - usually the name of the main chain param)
get($param [, $prefixed = true])
boolean(true / false)
mixed(the current value of the field)
All core gizmos, and any custom gizmo you create, should extend this GantryGizmo class. To create a new gizmo of your own, you would just have to create a new file in your
gizmos/ folder that extended the GantryGizmo class. It will automatically be picked up by the Gantry framework and processed. The best way to see what one can do for you is to examine a few of the core gizmos.
First, let's look at one of the core gizmos called
analytics.php. As you can imagine, the analytics gizmo is intended to add the Google Analytics tracking code to your site. The most important part of a gizmo is the actual gizmo PHP file. The core gizmos are located in the
YOUR_SITE/wp-content/plugins/gantry/gizmos/ folder. These should never be touched or changed.
If you want to override the behavior of a core gizmo, simply copy the core gizmo to your
YOUR_SITE/wp-content/themes/YOUR_TEMPLATE/gizmos 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 gizmo, 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 Google Analytics gizmo, the section in templateDetails.xml looks like:
<fields name="analytics" type="chain" label="Analytics"> <field name="enabled" type="toggle" default="0" label="Enable" /> <field name="code" type="text" default="" label="Code" class="text-long" /> <field name="priority" type="hidden" default="3"/> </fields>
What this means is that in the administrator interface, there are going to be two parameters rendered. One is a toggle element that will control the 'enabled' state. The second is a text input for your unique Analytics key that will be added to the JS script. 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. They would be available for you to use in your gizmos PHP definition.
Next, let's look at the PHP for this feature:
As you can see, the only method that is used is the
init() method. Other methods from the base GantryGizmo class are not overridden. That means that the standard methods (to get the enabled state, etc.) are being used, and are pulling that data from the XML, in addition to the admin settings. You can see how custom XML parameters like code are easily available, and are automatically prefixed by the gizmo name. This allows you to just use
get->("code") to retrieve the value of of a chained field.
Have a look through all the default gizmos that come with Gantry to see how you can achieve a wide variety of functionality with these incredible tools.