head     1.1;
branch   1.1.1;
access   ;
symbols  start:1.1.1.1 swish-e:1.1.1;
locks    ; strict;
comment  @# @;


1.1
date     2005.01.18.20.32.49;  author whmoseley;  state Exp;
branches 1.1.1.1;
next     ;

1.1.1.1
date     2005.01.18.20.32.49;  author whmoseley;  state Exp;
branches ;
next     ;


desc
@@



1.1
log
@Initial revision
@
text
@[%
    # Macro passes in 
    #   "target"            a menu id in config/map
    #   "text"              optional text to use instead of link text
    #   "return_link_only   optional flag to say return only the href
    # Link text is NOT html escaped.
    # Note that there's nothing to prevent a map/menu from having two menu items
    # at different levels from having the same id.  Therefore, this processes each
    # menu level before recursing, so it should find top level ids first.

    # TODO
    # - allow passing in a tooltip (title)
    # - set class attribute saying if internal or external link.


    SET global.link_found = 0;  # to track when found so can stop recursing


    SET fragment    = target.replace('^[^#]+','');
    SET target_id   = target.replace('#.+$','');

    link = INCLUDE look_for_link;

    THROW 'menu', "Failed to find menu link for target '$target_id' from page $template.name"
        UNLESS link;
    link;
-%]
[%- BLOCK look_for_link;

    # Finds an entry in the site map. Call with the link_to_page(id) macro
    # TODO - make abort if not found

    subdirs = [];

    FOREACH id = map.page.keys;
        item = map.page.$id;

        # Is there a sub menu that should be looked through later?
        subdirs.push( item ) IF item.page;

        # Is this the item we are looking for?
        NEXT UNLESS id == target_id;

        global.link_found = 1;

        SET href = "${item.url}$fragment";

        IF return_link_only;
            href;
            RETURN;
        END;

        "<a href=\"$href\"";
        " title=\"${item.tooltip}\"" IF item.tooltip;
        ">";
        text || item.name;
        "</a>";


        RETURN;
    END;


    FOREACH item = subdirs;
        LAST IF global.link_found;
        INCLUDE look_for_link map = item;
    END;

END -%]
@


1.1.1.1
log
@Initial import
@
text
@@
