Документация
HTML CSS PHP PERL другое

11.9 Making It Mature, Part 3

 
Previous Table of Contents Next

11.9 Making It Mature, Part 3

The next step consists of removing two lines of code. Specifically, lines 25 and 47. Why? Because they handle a normal case of user error, and we'd prefer that those error messages be under the control of the person who's got the job of editing our output templates. By using the knowledge that a <TMPL_IF> tag that names a loop will evaluate as true only if there is at least one item in the loop, we can handle the same condition in output.tmpl:

Example 11.15. output.tmpl, Version 3

<HTML><HEAD>

 <TITLE>

  <TMPL_IF NAME="results">

   Search Results

  <TMPL_ELSE>

   Error

  </TMPL_IF>

 </TITLE>

</HEAD>

 <BODY>

  <TMPL_IF NAME="results">

   <H1>Results of search for <TMPL_VAR NAME="filter"></H1>

   <TABLE BORDER="1">

    <TR>

     <TMPL_LOOP NAME="attributes">

      <TH><TMPL_VAR NAME="attribute"></TH>

     </TMPL_LOOP>

    </TR>

    <TMPL_LOOP NAME="results">

     <TR>

      <TMPL_LOOP NAME="attributes">

      <TD><TMPL_VAR NAME="attribute"></TD>

      </TMPL_LOOP>

     </TR>

    </TMPL_LOOP>

   </TABLE>

  <TMPL_ELSE>

   <H1>Error: No match for <TMPL_VAR NAME="filter"></H1>

  </TMPL_IF>

 </BODY>

</HTML>

    Previous Table of Contents Next
    © 2000- NIV