Siblings with Input Data Example

A list of users is defined using the XmlDataTable macro. The result is then filtered to remove all user ids less than zero.

The filtered data table is then passed to the siblings macro which generates links to other users. The links work by adding the current user id to the query string. Siblings needs a currentkey to work, so there is a default of 5 (Grumpy) given to the save buffer "userid" when it's read from the query string, which is later passed to the currentkey parameter.

Smartsite SXML CopyCode image Copy Code
<!--// This is our test data. -->
<se:xmldatatable save="userdata" resulttype="datatable">
    <se:row><se:col name="nr">-1</se:col><se:col name="fullname">Grimm brothers</se:col></se:row>
    <se:row><se:col>1</se:col><se:col>Snow white</se:col></se:row>
    <se:row><se:col>2</se:col><se:col>Bashful</se:col></se:row>
    <se:row><se:col>3</se:col><se:col>Doc</se:col></se:row>
    <se:row><se:col>4</se:col><se:col>Dopey</se:col></se:row>
    <se:row><se:col>5</se:col><se:col>Grumpy</se:col></se:row>
    <se:row><se:col>6</se:col><se:col>Happy</se:col></se:row>
    <se:row><se:col>7</se:col><se:col>Sleepy</se:col></se:row>
    <se:row><se:col>8</se:col><se:col>Sneezy</se:col></se:row>
</se:xmldatatable>    

<!--// Get the user id from the querystring or use Grumpy as the default user. -->
<se:text save="userid">{request.query(userid, default=5)}</se:text>

<!--// Remove users with a negative nr field. -->
<se:filter save="userdata" resulttype="datatable">
<se:parameters>
    <se:parameter name="inputdata">userdata</se:parameter>
    <se:parameter name="rowfilter">nr&gt;0</se:parameter>
    </se:parameters>
</se:filter>

<!--// Use the siblings macro to browse our snow white and the dwarfs. -->
<se:siblings>
<se:parameters>
    <se:parameter name="inputdata">userdata</se:parameter>
    <se:parameter name="currentkey">{buffer.get(userid)}</se:parameter>
    <se:parameter name="siblingorder">first,back,next,last</se:parameter>
    
    <se:parameter name="format">
    
        <se:rowformat>
            <span class="sib{this.field(rowname)}">{this.field(display)}</span>
            </se:rowformat>
        <se:rowformat expression="this.field(exists)">
            <a href="{url.addparameter(channel.link(itemdata.number()),user,this.field(nr))}" title="{this.field(fullname)}" class="sib{this.field(rowname)}">
                {this.field(display)}
                </a>
            </se:rowformat>
        <se:captionformat expression="this.rownr()==3">{this.currentindex()}/{this.siblingcount()}</se:captionformat>
        </se:parameter>
    </se:parameters>
</se:siblings>
Example Result CopyCode image Copy Code
<a href="/test.net?id=3820&amp;user=1" title="Snow white" class="sibFirst">
                |&lt;
                </a>
            
            <a href="/test.net?id=3820&amp;user=4" title="Dopey" class="sibBack">
                &lt;
                </a>
            5/8
            <a href="/test.net?id=3820&amp;user=6" title="Happy" class="sibNext">
                &gt;
                </a>
            
            <a href="/test.net?id=3820&amp;user=8" title="Sneezy" class="sibLast">
                &gt;|
                </a>