3.3 Using the snaps taglibs
Prev | 3. Using Virgo Snaps in your application | Next

## 3.3 Using the snaps taglibs

There is a tag library available that makes information about the snaps environment available to the host from within a JSP page. The prefix and URI to declare are `<%@ taglib prefix="snaps" uri="http://www.eclipse.org/virgo/snaps" %>`. You can now access an array of all the Snaps currently registered with the host. Each Snap in the array has two values, the first is the context path the Snap is registered with, as given in the Snaps manifest header. The second is an array of properties, if any, given in a property file in the Snap. The file must be in the `META-INF` and have a name of `snap.properties`. The following code snippet shows all of these in use to produce links to each of the installed Snaps.

    <snaps:snaps var="snaps">
        <c:forEach var="snap" items="${snaps}">
            <a href="<c:url value="${snap.contextPath}${snap.properties['link.path']}"/>">
                         ${snap.properties['link.text']}</a>
        </c:forEach>
    </snaps:snaps>

The first line uses the Snaps tag library to place the array of Snaps in to the `snaps` variable. Then a `forEach` loop goes through each Snap. The middle line is the really interesting one. The first variable looks up `${snap.contextPath}` which will return the context path of the snap. The second two lookups are for properties `${snap.properties['something']}`. They rely on the Snap having the properties file in place with `link.path` and `link.text` defined in it. This shows the flexibility you have for defining your own contract between the host and its Snaps. In this case the Snap can contribute extra information about how links in a menu should be constructed.

Prev | Up | Next
3.2 Configuring a Snap | Home | 3.4 Referencing resources