Templates in Basildon are all written in the Twig templating language. They can output any format that's required. Basildon provides a few variables functions, and filters for common website use cases; these are explained on this page.
Variables
-
page
– An object representing the current page being rendered. It has the following members:-
page.body
: The unmodified body text, good for piping through filters such asmd2html
andmd2latex
. -
page.metadata
: All the metadata defined in the page's frontmatter. -
page.link(target)
: Creates a relative URL to another page.
-
-
database
- The database, the most useful attribute of which isdatabase.query(sql)
. -
site
– The site object, mostly used to access configuration values, e.g.site.config.title
.
Functions
-
commons(file_name)
– Get information about a Wikimedia Commons file. -
flickr(photo_id)
– Get information about a Flickr photo. To use this, you need to set theflickr.api_key
andflickr.api_secret
values in your site'sconfig.local.yaml
file. -
qrcode(text)
– Returns an asset-directory path to a QR code SVG file, such as/assets/8a482ae2afb51a1de85b7eb9087f7cc2.svg
. For example:<img src="{{ page.link(qrcode('string')) }}" />
-
wikidata(qid)
– Returns information about the given Wikidata item. For example,{{ wikidata('Q42').descriptions.en.value }}
will return something like "English writer and humorist". To get the full details of the returned structure, see e.g. wikidata.org/wiki/Special:EntityData/Q42.json. -
wikidata_query(sparql)
— Returns the result of the Sparql query from Wikidata. See the example in /example/templates/tag.html.twig -
wikipedia(lang, title)
— Returns an HTML extract of the given article. For example:{{wikipedia('en', 'Tag (metadata)')|raw}}
Filters and escapers
-
md2html
– Filter markdown to HTML. -
md2latex
– Filter markdown to LaTeX. -
escape('tex')
– Escaper to use in TeX templates to escape characters that have special meaning in TeX, e.g.{{ '$10'|e('tex') }}
. This is often used by wrapping the template in{% autoescape 'tex' %}{% endautoescape %}
-
dirname
andbasename
— Identical to PHP's dirname() and basename() functions. Useful for working with Basildon page IDs.