Use the head and bottom template in the layer

how to use

Take a look at this example in the implementation, open the map in Example 3 and cancel the header and footer in the city area layer. Save MapFile when done。

The HEADER and FOOTER object keywords within the layer are used to define the template keywords used in the header and footer templates. You can uncomment the following two lines to see the template files themselves and see how they work.


HEADER '../templates/cities_header.html'
FOOTER '../templates/cities_footer.html'

Check the layer of "City" and click the "Refresh" button. The map will be refreshed and the city layer should now be displayed. Change the map mode to "Query Single Layer" or "Query Multiple Layers" and click on one of the cities.

The result should now have a heading and should be presented in tabular form

Here's what the cities_header.html looks like

    <b>Layer: cities</b>
  <p>
  <table cellpadding=5 cellspacing=2 border=0>
    <tr bgcolor=#CCCCCC>
      <td bgcolor=#ffffff> </td>
      <th>NAME</th>
      <th>STATE</th>
    </tr>
Here again is the content of cities_query.html file
    <tr>
      <td>[lrn]</td>
      <td>[NAME]</td>
      <td>[STATE]</td>
    </tr>
And finally, here's what the cities_footer.html looks like
  </table>
  <p>

When MapServer processes the query for a particular layer, it first looks for a header template for that layer. It will then process the records that it gets back from the database, applying the query template for each record. When the template has been applied to all records, it will again look for the footer template for the layer. View the source of the query result page to see how this works

View the MapFile | View the HTML Template

Open the example

7    FONTSET "../fonts/fonts.list"7    FONTSET "../fonts/fonts.list"
n8    TEMPLATEPATTERN "tmpl-*"n8    TEMPLATEPATTERN "example-p*"
9    LEGEND9    LEGEND
17    END17    END
n18    SYMBOLn
19        NAME "star"
20        TYPE VECTOR
21        FILLED TRUE
22        POINTS
23            0 0.375
24            0.35 0.375
25            0.5 0
26            0.65 0.375
27            1 0.375
28            0.75 0.625
29            0.875 1
30            0.5 0.75
31            0.125 1
32            0.25 0.625
33        END
34    END
35    REFERENCE18    REFERENCE
36        IMAGE "../images/worldref.png"19        IMAGE "../images/worldref.png"
n37        SIZE 300 150n20        SIZE 155 105
38        EXTENT -180 -90 180 9021        EXTENT -180 -90 180 90
39        STATUS ON22        STATUS ON
n40        MINBOXSIZE 30n23        MINBOXSIZE 10
41        MAXBOXSIZE 15024        MAXBOXSIZE 150
n42        COLOR 255 255 0n25        COLOR -1 -1 -1
43        OUTLINECOLOR 255 55026        OUTLINECOLOR 120 0
44        MARKERSIZE 3027        MARKERSIZE 8
45        MARKER "star"28        MARKER "star"
n46    ENDn
47    QUERYMAP
48        SIZE 200 150
49        STATUS ON
50        STYLE HILITE
51        COLOR 255 0 0
52    END29    END
59        STYLE 136        STYLE 1
n60        SIZE 160 2n37        SIZE 100 2
61        COLOR 0 0 038        COLOR 0 0 0
n62        UNITS KILOMETERSn39        UNITS MILES
63        INTERVALS 240        INTERVALS 2
67    WEB44    WEB
n68        HEADER "qtpl_header.html"n
69        FOOTER "qtpl_footer.html"
70        TEMPLATE "to be replaced by map_web_template variable in section3.html"45        TEMPLATE "to be replaced by map_web_template variable in section3.html"
79    LAYER54    LAYER
n80        NAME "land"n55        NAME "topo"
81        DATA "land_shallow_topo_8192.tif"56        DATA "land_shallow_topo_8192.tif"
83        TYPE RASTER58        TYPE RASTER
nn59        PROCESSING "BANDS=1,2,3"
60        OFFSITE 71 74 65
84    END61    END
85    LAYER62    LAYER
n86        NAME "topo"n63        NAME "modis_jpl"
87        TYPE RASTER64        TYPE RASTER
nn65        OFFSITE 0 0 0
66        STATUS OFF
88        CONNECTIONTYPE WMS67        CONNECTIONTYPE WMS
106        LABELITEM "NAME"85        LABELITEM "NAME"
nn86        HEADER "../maptmpl/states_header.html"
87        FOOTER "../maptmpl/states_footer.html"
107        TOLERANCE 388        TOLERANCE 3
109            NAME "the States"90            NAME "the States"
n110            TEMPLATE "qtpl_country.html"n91            TEMPLATE "../maptmpl/states_query.html"
111            STYLE92            STYLE
131        DATA "wriver.shp"112        DATA "wriver.shp"
n132        STATUS ONn113        STATUS OFF
133        TYPE LINE114        TYPE LINE
n134        TOLERANCE 3n
135        CLASS115        CLASS
136            NAME "World River"116            NAME "World River"
t137            TEMPLATE "qtpl_river.html"t
138            STYLE117            STYLE