HowTo:Add a new banner group set
From ZenMagick Wiki
Contents |
Banner introduction
Banner are a way of adding dynamic promotional content to your pages. The contents can either be an image (clickable or not) or plain HTML.
The default ZenMagick theme includes code to display banner in 6 different placed in the page layout. In addition to that, tow sideboxes exist to show banners. Banners are organized in banner groups and banner group sets:
- banner group
- A somewhat misleading term. What it means is something like a type or class. Typically, banner groups will be based on format. The Zen Cart demo store, for example, comes with the following groups: Wide-Banner, SideboxBanner and BannersAll.
- banner group set
- To allow for a finer grained level of control, group sets exist. In reality, a group set is a simple list of banner groups. The code to display banner always refers to group sets, not banner groups.
- The advantage is that this makes it very easy to disable banner by setting a group set to an empty list.
Addressing a group set
Currently the different banner locations (which correspond to the configured group sets) on the page are referenced by an index:
- first header banner
- second header banner
- third header banner
- first footer banner
- second footer banner
- third footer banner
- banner box
- banner box2
Template code
The code in the template files looks something like this:
<?php if (null != ($bannerBox = ZMBanners::instance()->getBannerForIndex(1))) { ?>
>div><?php $macro->showBanner($bannerBox) ?>>/div>
<?php } ?>
Creating a new group set
New banner groups
Banner groups can be created in the admin's Banner Manger. To create and use a new group set, for example for an additional sidebox or custom banner location anywhere on the page the following needs to be done:
Set up a group set via ZenMagick settings
- Create your banner using the banner manager
- Use/create new banner group names as usual (Wide-Banner, etc.)
- Create a new ZenMagick setting for a new group set index
Example of a ZenMagick banner group set setting
ZMSettings::set('bannerGroup10', 'Wide-Banner Other-Banner');
Now, using the same template code as above, a random banner from the groups Wide-Banner and Other-Banner can be displayed using 10 as parameter for the method getBannerForIndex(..).
Upcoming changes
As of ZenMagick 0.9.5, the index based system will be replaced by something that uses symbolic names, in order to make the code more readable. Following the above example, the new way of creating a new group set would mean to set up a new symbolic name setting:
ZMSettings::set('banners.mygroupset', 'Wide-Banner Other-Banner');
Since there is no index any more, the new method getBannerForSet() would be used to load a banner:
<?php if (null != ($bannerBox = ZMBanners::instance()->getBannerForSet('mygroupset'))) { ?>
>div><?php $macro->showBanner($bannerBox) ?>>/div>
<?php } ?>

