About Sitellite       Screenshots       Downloads       Forge      Documentation       Community       Support

You are here: Home / Documentation / How To: XT Template Essentials

How To: XT Template Essentials

Includes

While boxes are the preferred method of inclusion in Sitellite, as they adhere to Sitellite's automatic access control and configuration facilities, I will still document includes here as well, since they can present an elegant, simple, and often powerful solution to certain problems.

First, let's look at the most basic file inclusion:

<xt:tpl>
    <xt:inc name="footer.html" type="plain" />
</xt:tpl>

This will include the file footer.html into your template, treating it as a literal inclusion (ie. not performing any transformation on it at all).  As you can see, the lack of transformation is due to the type="plain" attribute.  The default inclusion type (ie. when no type is specified at all) will treat the included file as an XT template itself, and transform it prior to inserting it into the current template.

Next, let's look at the real potential includes possess in maintaining previewability.

<xt:tpl>
    <xt:inc name="footer.html" type="plain">
        <p>
            This is some temporary text that will be replaced
            by the file footer.html when this template is
            rendered in Sitellite.
        </p>
    </xt:inc>
</xt:tpl>

As you can see, the ability to specify fake data, including XHTML tags, is a powerful feature of the XT template system.

Finally, before moving on to boxes, let's take the include facilities to a new level, and include content from another web site.  But even better, let's include headlines from another web site, pulled from an RSS file.

<xt:tpl>
    <ul>
        <xt:inc
            name="http://slashdot.org/index.rss"
            type="xml"
            item="/rdf:RDF/item">
            <li>
               <a href="${xml/link}" xt:content="xml/title">Title</a>
                <span xt:replace="xml/description">Description</span>
            </li>
        </xt:inc>
    </ul>
</xt:tpl>

Pretty cool, eh?  However, please beware that while this capability looks really cool, it is not a complete example yet.  To be respectful of other web sites, you should always cache RSS feeds locally and only request them periodically -- otherwise for each visitor to your site, there's another retrieval of the file from their site.  To finish this example then, you'll want to add the following to the template:

<xt:tpl>

    <xt:cache scope="application" duration="3600">

    <ul>
        <xt:inc
            name="http://slashdot.org/index.rss"
            type="xml"
            item="/rdf:RDF/item">
            <li>
                <a href="${xml/link}" xt:content="xml/title">Title</a>
                <span xt:replace="xml/description">Description</span>
            </li>
        </xt:inc>
    </ul>

    </xt:cache>

</xt:tpl>

Please note: If you run into errors with caching, make sure the cache folder and those inside of it are writeable by Sitellite.

Next Up: Boxes

Page 1: Introduction
Page 2: First Steps
Page 3: Substitutions (Part 2)
Page 4: Conditions
Page 5: Loops
Page 6: Includes
Page 7: Boxes
Page 8: I18n
Page 9: XT Object Reference

All Tutorials

Members

Note: You can use your SitelliteForge.com account here and vice versa.

Username

Password

Forgot your password?

Not a member? Click here to register

Sitellite 5 Beta


Copyright © 2008, SIMIAN systems Inc.
All rights reserved. Privacy policy
Some of the icons on this site were created by the Gnome Project.