Skip to content

Twig

phil/geo-bundle
NameKindGives
geo_distance(from, to)functionThe Distance between two Coordinates; null when either is missing
format_distance(locale = null, system = 'metric')filter850 m, 12,3 km in fr_CA; 7.7 mi with imperial; empty for null
geo_attributes(position, decimals = 7)function, safe HTMLThe attributes of a place the distance-sort controller sorts: its target and its position, to that many decimals
{{ geo_distance(here, store.position)|format_distance }}
<li {{ geo_attributes(store.position, 3) }}>{{ store.name }}</li>

format_distance builds one number formatter per locale and keeps those of 64 locales at most, so that locales taken from requests cannot grow the memory of a worker that lives across requests.

schema.org

FunctionGives
geo_schema(coordinates)The coordinates as schema.org GeoCoordinates, or null

The data composes into a JSON-LD document printed by the template:

<script type="application/ld+json">{{ data|json_encode(constant('JSON_UNESCAPED_SLASHES') b-or constant('JSON_UNESCAPED_UNICODE') b-or constant('JSON_HEX_TAG'))|raw }}</script>

JSON_HEX_TAG writes < and > as escapes, so no value can close the script element.