configuration.rst 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. .. _community_wfsfreemarker_config:
  2. WFS FreeMarker Extension configuration
  3. ======================================
  4. Template Lookup
  5. ```````````````
  6. Reference: :ref:`tutorials_getfeatureinfo`
  7. Example Configuration on a Vector Layer
  8. ``````````````````````````````````````````
  9. The WFS GetFeature can generate output in various formats: GML, GeoJSON, ... and, through this extension, also HTML.
  10. WFS Templating is concerned with the HTML one.
  11. Assume we have a Vectorial layer named :guilabel:`geosolutions:bplandmarks`
  12. #. Go to the Layer preview to show :guilabel:`geosolutions:bplandmarks` layer.
  13. #. Search for the HTML format from the :guilabel:`All Formats` select-box, under the WFS ones.
  14. .. figure:: images/info1.png
  15. #. In order to configure a custom template of the GetFeature results create three files ``.ftl`` in ``$geoserver_data/workspaces/geosolutions`` directory named:
  16. .. code::
  17. - header.ftl
  18. - content.ftl
  19. - footer.ftl
  20. .. note::
  21. The Template is managed using Freemarker. This is a simple yet powerful template engine that GeoServer uses whenever developers allowed user customization of textual outputs. In particular, at the time of writing, it’s used to allow customization of GetFeatureInfo, GeoRSS and KML outputs.
  22. .. note::
  23. Splitting the template in three files allows the administrator to keep a consistent styling for the GetFeatureInfo result, but use different templates for different workspaces or different layers. This is done by providing a master header.ftl and footer.ftl file, but specify a different content.ftl for each layer.
  24. #. In header.ftl file enter the following HTML:
  25. .. code::
  26. <#--
  27. Header section of the GetFeatureInfo HTML output. Should have the <head> section, and
  28. a starter of the <body>. It is advised that eventual CSS uses a special class for featureInfo,
  29. since the generated HTML may blend with another page changing its aspect when using generic classes
  30. like td, tr, and so on.
  31. -->
  32. <html>
  33. <head>
  34. <title>Geoserver GetFeatureInfo output</title>
  35. </head>
  36. <style type="text/css">
  37. table.featureInfo, table.featureInfo td, table.featureInfo th {
  38. border:1px solid #ddd;
  39. border-collapse:collapse;
  40. margin:0;
  41. padding:0;
  42. font-size: 90%;
  43. padding:.2em .1em;
  44. }
  45. table.featureInfo th{
  46. padding:.2em .2em;
  47. text-transform:uppercase;
  48. font-weight:bold;
  49. background:#eee;
  50. }
  51. table.featureInfo td{
  52. background:#fff;
  53. }
  54. table.featureInfo tr.odd td{
  55. background:#eee;
  56. }
  57. table.featureInfo caption{
  58. text-align:left;
  59. font-size:100%;
  60. font-weight:bold;
  61. text-transform:uppercase;
  62. padding:.2em .2em;
  63. }
  64. </style>
  65. <body>
  66. #. In content.ftl file enter the following HTML:
  67. .. code::
  68. <ul>
  69. <#list features as feature>
  70. <li><b>Type: ${type.name}</b> (id: <em>${feature.fid}</em>):
  71. <ul>
  72. <#list feature.attributes as attribute>
  73. <#if !attribute.isGeometry>
  74. <li>${attribute.name}: ${attribute.value}</li>
  75. </#if>
  76. </#list>
  77. </ul>
  78. </li>
  79. </#list>
  80. </ul>
  81. #. In footer.ftl file enter the following HTML:
  82. .. code::
  83. <#--
  84. Footer section of the GetFeatureInfo HTML output. Should close the body and the html tag.
  85. -->
  86. </body>
  87. </html>
  88. #. Refresh the WFS GetFeature HTML output
  89. .. figure:: images/info2.png