.. _template-directives: Template Directives =================== This part of the documentation is an introduction explaining the different template directives. Examples will be provided for both Simple Features and Complex Features. The syntax of the directives varies slightly between XML based templates and JSON based templates. The examples will be provided mainly for GeoJSON and GML. However the syntax defined for GeoJSON output, unless otherwise specified, is valid for JSON-LD templates Template directive summary -------------------------- The following constitutes a summary of all the template directives and it is meant to be used for quick reference. Each directive is explained in detail in the sections below. JSON based templates ^^^^^^^^^^^^^^^^^^^^ The following are the directives available in JSON based templates. .. list-table:: :widths: 30 10 60 * - **Usage** - **Syntax** - **Description** * - property interpolation - ${property} - specify it as an attribute value (:code:`"json_attribute":"${property}"`) * - cql evaluation - $${cql} - specify it as an element value (:code:`"json_attribute":"$${cql}"`) * - setting the evaluation context for child attributes. - ${source}. - specify it as the first nested object in arrays (:code:`{"$source":"property"}`) or as an attribute in objects (:code:`"$source":"property"`) * - filter the array, object, attribute - $filter - specify it inside the first nested object in arrays (:code:`{"$filter":"condition"}`) or as an attribute in objects (:code:`"$filter":"condition"`) or in an attribute next to the attribute value separated by a :code:`,` (:code:`"attribute":"$filter{condition}, ${property}"`) * - defines options to customize the output outside of a feature scope - $options - specify it at the top of the JSON template as a JSON object (GeoJSON options: :code:`"$options":{"flat_output":true, "separator":"."}`; JSON-LD options: :code:`"$options":{"@context": "the context json", "encode_as_string": true, "@type":"schema:SpecialAnnouncement", "collection_name":"customCollectionName"}`). * - allows including a template into another - $include, $includeFlat - specify the :code:`$include` option as an attribute value (:code:`"attribute":"$include{subProperty.json}"`) and the :code:`$includeFlat` as an attribute name with the included template path as a value (:code:`"$includeFlat":"included.json"`) * - allows a template to extend another template - $merge - specify the :code:`$merge` directive as an attribute name containing the path to the extended template (:code: `"$merged":"base_template.json"`). * - allows null values to be encoded. default is not encoded. - ${property}! or $${expression}! - ! at the end of a property interpolation or cql directive (:code:`"attribute":"${property}!"` or :code:`"attribute":"$${expression}!"`). XML based templates ^^^^^^^^^^^^^^^^^^^^ The following are the directives available in XML based templates. .. list-table:: :widths: 30 10 60 * - **Usage** - **Syntax** - **Description** * - property interpolation - ${property} - specify it either as an element value (:code:`${property}`) or as an xml attribute value (:code:``) * - cql evaluation - $${cql} - specify them either as an element value (:code:`$${cql}`) or as an xml attribute value (:code:``) * - setting the evaluation context for property interpolation and cql evaluation in child elements. - gft:source - specify it as an xml attribute (:code:``) * - filter the element to which is applied based on the defined condition - gft:filter - specify it as an XML attribute on the element to be filtered (:code:``) * - marks the beginning of an XML template. - gft:Template - It has to be the root element of an XML template (:code:` Template content`) * - defines options to customize the output outside of a feature scope - gft:Options - specify it as an element at the beginning of the xml document after the :code:`` one (:code:``). GML options: :code:``,:code:``. HTML options: :code:`