4. Grouping elements

Grouping elements is a simple way to make a site more strictly structured. Global variables that are defined inside a group are only available within the group. The same is true for global exits. A group also allows you to setup inheritance for a number of elements without having to resort to a subsite. A handy side-effect of using a group is that only the global variables inside the group are reset when a departure is called.

Grouping elements is done in the site definition by placing the elements in a group tag.

You can think of groups as subsites, with the distinct difference that they aren't declared in a different XML file and they have no unique id or url prefix.

Example 9.7. Showing the group tag being used

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE site SYSTEM "/dtd/site.dtd">
  <element id="HOME" file="home.xml" url="/home" />
    <globalexit name="menu" destid="ADMIN_MENU"/>
    <element id="ADD_USER" file="add-user.xml" url="/add_user" />
    <element id="DEL_USER" file="del-user.xml" url="/del_user" />

    <element id="ADMIN_MENU" file="admin-menu.xml" url="/admin_menu" />

    <globalexit name="menu" destid="SETTINGS_MENU"/>

    <element id="THEME" file="theme.xml" url="/theme" />
    <element id="LANG" file="lang.xml" url="/lang" />

    <element id="SETTINGS_MENU" file="settings-menu.xml" url="/settings-menu" />

Example 9.7, “Showing the group tag being used” shows two different groups, one for settings and one for administration. When a user goes to the settings part of the site he can go to the settings menu and when he goes to the admin part of the site he can go to the admin menu. Notice how the names of both the global exits are menu. This is possible since they are defined in different groups.