9.8.1 Query Markup - Multiple Variables

In our patent example's <details> function, we have only one variable to mark up with a query. But sometimes we'll be displaying many variables from a search, and it may get cumbersome to have to call <fmt> for every one. With <fmtcp> and <mm> , we can simplify this.

Let's say we're selecting the author, title, and description of a book in our details function, instead of just a patent abstract. We want to highlight the user's query in each of these variables. With the following code snippet we can do that for multiple variables:


  <fmtcp query "%mbH" $query>
  <SQL "select Author, Title, Desc
        from books
        where id = $id">
    <mm>
      $Title (by $Author) <BR>
      $Desc
      <P>
    </mm>
  </SQL>

Here we call <fmtcp nbsp;query> to set the format code and query we're going to use to mark up. This doesn't display anything yet, it just lets Vortex know what we're up to. We give it the same format and query we'd give to <fmt> .

Inside the <SQL> block, we've got 3 variables from our book to display with markup. We call <mm> to turn on highlighting (using our query we just set). Now, any variables that we simply print out, are automatically highlighted with our query. We then turn off highlighting with </mm> (in case we want to skip highlighting some other variable).

This keeps our HTML formatting neat inside the <SQL> block, without the clutter of multiple <fmt> calls. Note that only variables are marked up, not our hard-coded HTML tags, which is what we want.

(It is useful to note here that the <mm> and </mm> tags do not need to match up the way most start/end loop tags do in Vortex. The calls could even be in separate functions if we wanted.)

Back: Query Markup Next: Paginating Results
Copyright © 2024 Thunderstone Software LLC. All rights reserved.