Page Templates

The basics

DiF supports Web Page templates.
Through the component library DiF enables web page developers to use any stage as a template.

Basically there are two components that enable to use of page templates on DiF.

  • The document tag component

    Is the base component for all pages. The templateID attribute specifies the ID of the stage to be used has a template.
    When this attribute is used the current page is rendered inside the template stage.

  • The pageContent tag component

    Is the component that we use inside template stages. It includes the page content in the proper place inside the template layout.
    This will become clearer in the next example.

A simple example

A simple example follows to best show how to use the page templates:

The template stage.

This can be any normal stage we create. It can contain whatever HTML, components or other stages as we see fit.
There are absolutely no restrictions for template development in comparison to stage development.
On top of the normal functionalities there are only two new features we can use exclusively in template stages.

  • A new content variable inside the document tag called contentStage. This will enable access to all the included main stage resources since the normal stage variable will reference the template stage itself.
  • The pageContent tag component, that allows us to specify to DiF where to include the page stage content on.
<%@ page language="java"%>
<%@ taglib uri="/difcore" prefix="dif"%>
<dif:document>
    <dif:contribution id="css:template" type="css_file" fileURL="css/css_diftemplate.css" />
    <dif:component stageID="header" />
    <dif:component stageID="leftnavbar" />
    <div id="contentonecolumn"><dif:breadcrumbs cssClass="breadcrumbs" />
    <h3>${contentStage.messages.title}</h3>
    <dif:actions>
        <dif:actionItem type="send" />
        <dif:actionItem type="save" />
        <dif:actionItem type="print" />
        <dif:actionItem type="help" />
    </dif:actions>
    <div class="content"><dif:pageContent /> </dif><dif:actions>
        <dif:actionItem type="top" />
    </dif:actions></div>
    <dif:component stageID="footer" />
</dif:document>

The previous example is taken from an actual template for all DiF internal pages.
We can see the use of inner stages as components and content from the stage and contentStage variables.

The pages that use the template

These only have to indicate the usage of a given template, through the templateID attribute. Like the following example:

<%@ page language="java"%>
<%@ taglib uri="/difcore" prefix="dif"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<dif:document templateID="diftemplate">
    <p>${messages.pageDesc}</p>
    <dif:parameterErrors />
    
    <c:if test="${!empty stage.errorMessage}">
        <dif:alertBox>${stage.errorMessage}</dif:alertBox>
    </c:if>
    
    <dif:form name="login">
        <dif:fieldset title="${messages.pageHeading}">
            <input name="afterloginstageid" type="hidden" value="${stage.afterLoginStageID}" />
            <dif:textField id="_user" />
            <dif:textField id="_pass" confidential="true" />
        </dif:fieldset>
        <input type="submit" name="${messages.submit}" />
    </dif:form>
</dif:document>

This is an actual code sample from DiF's internal login page. A normal stage that indicates the usage of the diftemplate page template.

DiF default page template

Like we saw in the above examples DiF includes in it's default stages a page template called diftemplate.
This can be used by your own pages.

This template includes features like:

  • Login/logout box
  • View mode switcher
  • Language selector
  • Content menu
  • Footer
  • Etc.

What this provides

DiF page template features gives all the functionality of a normal page to a template.
Unlike the majority of JSP based web frameworks (and many other non JSP based ones) DiF breaks down the normal limitations of JSP usage for page/component inclusions, making dead simple the usage of pages as components and templates.
Any number of component/templates inside pages can be used without limitations other that weighting the processing time of the desired features in use.

The id reference to templates further allows developers to loosely link all pages to a given template that is referenced only by stage name.
This means that at load time any specific page template can be provided with this referenced id and will be linked to the pages.
This is most useful for largely distributed applications that need to be extensively customized to be used inside each client's Internet/Intranet pages/applications with an already defined user interface and specific web design.

Back to User Guide index