#### 37.4.4 Using macros to process lists

Suppose you want to generate a different set of sidebar navigation links for each major section of a Web site, where each section is in a single DITA file that DITA2Go splits into named pages (see §27. Splitting and extracting files). For each page, the sidebar item that names that page should not be a link, because a live link to the current page confuses people.

You need a slightly different list of sidebar items on every HTML page, to avoid a same-page link. But the logic is always the same, as are the names of files and the titles to be displayed. What is needed is a macro that takes into account which item should not be linked.

Your configuration file could include a pair of lists, one with file names and the other with matching sidebar titles, like this:

    [DITA_File]
    1 = homepage
    2 = descript
    3 = operate
    4 = testimonial
    5 = demo
    6 = order

    [SideTitle]
    1 = Widgets
    2 = What a Widget Does
    3 = How to Use a Widget
    4 = What Users Say About Widgets
    5 = Get a Demo Widget
    6 = Order Widgets On Line

You could process the two lists with this macro:

    [Sidebar]
    <$$val=2><$$maxval=6>\
    <$_while ($$val <= $$maxval)>\
      <$_if ($$_currbase is $$DITA_File[$$val])>\
        <p class="SidebarTxt"><$$SideTitle[$$val]></p>\
        <$_else>\
        <p class="SidebarTxt"><a class="SidebarLnk"\
        href="<$$DITA_File[$$val]>.htm"><$$SideTitle[$$val]></a></p>\
        <$_endif>
      <$$val++>
      <$_endwhile>

Previous Topic: 37.4.3 Initializing list variables

Next Topic: 37.4.5 Using pointers to process lists

Parent Topic: 37.4 Using multiple-value list variables

Sibling Topics:

37.4.1 Understanding list-variable syntax

37.4.2 Assigning a value to a list-variable item

37.4.3 Initializing list variables

37.4.5 Using pointers to process lists

37.4.6 Using a list instead of a conditional expression