HTML Templates¶
Built-in templates are used for html generation.
Template override¶
To override an OGC API Features template:
Create a directory
ogc/features
in the location you wish to override:GEOSERVER_DATA_DIR/templates/ogc/features/v1
GEOSERVER_DATA_DIR/workspace/workspace/ogc/features/v1
GEOSERVER_DATA_DIR/workspace/workspace/datastore/ogc/features/v1
GEOSERVER_DATA_DIR/workspace/workspace/datastore/featuretype/ogc/features/v1
Create a file in this location, using the GeoServer 2.27-SNAPSHOT examples below:
The above built-in examples are for GeoServer 2.27-SNAPSHOT, please check for any changes when upgrading GeoServer.
Writing templates¶
For details on how to write templates see Freemarker Templates tutorial.
The following functions are specific to OGC API templates:
serviceLink(path*, format)
generates a link back to the same service. The first argument, mandatory, is the extra path after the service landing page, the second argument, optional, is the format to use for the link.genericServiceLink(path*, k1, v1, k2, v2, ....)
generates a link back to any GeoServer OGC service, with additional query parameters. The first argument, mandatory, is the extra path after the GeoServer context path (usually/geoserver
), the following arguments are key-value pairs to be added as query parameters to the link.resourceLink(path)
links to a static resource, such as a CSS file or an image. The argument is the path to the resource, relative to the GeoServer context path (usually/geoserver
).
List features¶
To override a template used to list features:
Use the directory in the location you wish to override (can be general, specific to a workspace, datastore, or feature type):
GEOSERVER_DATA_DIR/templates
GEOSERVER_DATA_DIR/workspace/workspace
GEOSERVER_DATA_DIR/workspace/workspace/datastore
GEOSERVER_DATA_DIR/workspace/workspace/datastore/featuretype
Create a file in this location, using the GeoServer 2.27-SNAPSHOT examples below:
The above built-in examples are for GeoServer 2.27-SNAPSHOT, please check for any changes when upgrading GeoServer.
Collection Example¶
Example showing how to customize a collections being listed:
The file
ogc/features/collections.ftl
lists published collection:<#global pagecrumbs> <li class='breadcrumb-item'><a href='${serviceLink("")}'>Home</a></li> <li class='breadcrumb-item active'>Collections</li> </#global> <#include "common-header.ftl"> <h1>GeoServer Feature Collections</h1> <p class="my-4"> This document lists all the collections available in the Features service.<br/> </p> <div class="row"> <#list model.collections as collection> <div class="col-xs-12 col-md-6 col-lg-4 pb-4"> <div class="card h-100"> <div class="card-header"> <h2><a href="${serviceLink("collections/${collection.id}")}">${collection.id}</a></h2> </div> <#include "collection_include.ftl"> </div> </div> </#list> </div> <script src="${resourceLink('webresources/ogcapi/features.js')}"></script> <input type="hidden" id="maxNumberOfFeaturesForPreview" value="${service.maxNumberOfFeaturesForPreview}"/> <#include "common-footer.ftl">
Save file to
GEOSERVER_DATA_DIR/workspace/templates/ogc/collections.ftl
, and rewrite as:<#include "common-header.ftl"> <h2>OGC API Feature Collections</h2> <p>List of collections published.</p> <p>See also: <#list model.getLinksExcept(null, "text/html") as link> <a href="${link.href}">${link.type}</a><#if link_has_next>, </#if></#list>.</p> <#list model.collections as collection> <h2><a href="${serviceLink("collections/${collection.id}")}">${collection.id}</a></h2> <#include "collection_include.ftl"> </#list> <#include "common-footer.ftl">
Many templates are constructed using
#include
, for examplecollection.ftl
above uses<#include "common-header.ftl">
located next tocollections.ftl
.Presently each family of templates manages its own
common-header.ftl
(as shown in the difference betweenogc/features
service templates, and getfeature templates above).A restart is not required, the system will notice when the template is updated and apply the changes automatically.
Template collections.ftl override applied¶
Language codes are appended for internationalization. For French create the file
GEOSERVER_DATA_DIR/workspace/workspace/ogc/collections_fr.ftl
and translate contents:<#include "common-header.ftl"> <h2>OGC API Feature Service</h2> <p>Liste des collections publiées.</p> <p>Voir également: <#list model.getLinksExcept(null, "text/html") as link> <a href="${link.href}">${link.type}</a><#if link_has_next>, </#if></#list>.</p> <#list model.collections as collection> <h2><a href="${serviceLink("collections/${collection.id}")}">${collection.id}</a></h2> <#include "collection_include.ftl"> </#list> <#include "common-footer.ftl">