#### 37.4.6 Using a list instead of a conditional expression

Suppose you want a different navigation bar for some of your HTML output files, depending on the name of the chapter from which the files are generated. One way would be to use a conditional expression (see §37.6.4.2 Using conditional expressions) to check the current chapter file name and choose the code for the navigation bar. For example:

    [NavBar]
    ; Configure navigation bar for roadmap:
    <$_if ($$_currbase is "user_roadmap")> <$rmap>
    ; Configure navigation bar for Programmer's Guide topics:
    <$_elseif ($$_currbase is "bgp_user")> <$pgnav>
    <$_elseif ($$_currbase is "mld_user")> <$pgnav>
     ... (long list of similar clauses)
    <$_elseif ($$_currbase is "pga_user")> <$pgnav>
    ; Configure navigation bar for function topics, by default:
    <$_else>
       <p>
       <a href="functions.htm">Function Index</a>
       </p>
    <$_endif>

Instead, you could use a list indexed by the value of $$_currbase, with each list value a macro call (or HTML code):

    [navmap]
    0 = <p><a href="functions.htm">Function Index</a></p>
    user_roadmap = <$rmap>
    bgp_user = <$pgnav>
    mld_user = <$pgnav>
     ...
    pga_user = <$pgnav>

    [NavBar]
    <$navmap[$$_currbase]>

The 0 (zero) list item corresponds to the <$_else> clause in the original [NavBar] macro, and is used if the specified index (the value of $$_currbase) is not found. Instead of a macro call the value of this list item is straight HTML code, which works as long as the code is all on one line. You could just as well use a macro call for the zero value, like the rest of the list items.

Previous Topic: 37.4.5 Using pointers to process lists

Next Topic: 37.5 Accessing settings with configuration macros

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.4 Using macros to process lists

37.4.5 Using pointers to process lists