<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;"># -------------------------------------------------------------------------------------
# flo::Template::Sibling
# -------------------------------------------------------------------------------------
#
#         Author : Jean-Michel Hiver (jhiver@cisedi.com)        (c) MKDoc Holdings Ltd.
#    Description : Provides the structure for the bread
#                  crumb trail loop.
#
#    &lt;% sibling set="Sibling" %&gt;
#    &lt;% var name="Sibling:Previous:URI" %&gt;
#    &lt;% var name="Sibling:Previous:Title" %&gt;
#    &lt;% var name="Sibling:Next:URI" %&gt;
#    &lt;% var name="Sibling:Next:Title" %&gt;
#
# -------------------------------------------------------------------------------------
package flo::Template::Sibling;
use lib::Template::AbstractTag;
use lib::Exception;
use lib::Template;
use flo::Standard;
use strict;
use vars qw /@ISA/;
@ISA = qw /lib::Template::AbstractTag/;


sub main
{
    my $self = shift;
    my $result = $self-&gt;result;
    my $tokens = $self-&gt;tokens;
    my ($token_name, $token_hash) = $self-&gt;parse_tag (shift @{$tokens});
    
    my $symbol = $token_hash-&gt;{set} or
        throw (new lib::Exception ( code =&gt; 'VARIABLE_NOT_SET',
                                    info =&gt; "$token_name should have a 'symbol' attribute" ) );
    
    my $document_table = table ('Document');
    my $document = $document_table-&gt;get ( Full_Path =&gt; path_info );
    
    # if this document is the root document, then @siblings is the document itself
    my @siblings = ();
    if ($document-&gt;Parent)
    {
	@siblings = $document-&gt;Parent-&gt;Children;
    }
    else
    {
	@siblings = $document;
    }
    
    # this hash will hold Previous and Next values
    my $hash = {
	Previous =&gt; undef,
	Next     =&gt; undef,
    };
    
    for (my $i=0; $i &lt; @siblings; $i++)
    {
	if ($siblings[$i]-&gt;ID == $document-&gt;ID)
	{
	    if ($i &gt; 0)         { $hash-&gt;{Previous} = $siblings[$i - 1] }
	    if ($i &lt; @siblings) { $hash-&gt;{Next}     = $siblings[$i + 1] } 
	    last;
	}
    }
    
    $lib::Template::STASH-&gt;{$symbol} = $hash;
}


1;
</pre></body></html>