Grow templates are stored in a pod's /views/ directory. Templates are processed using the Jinja2 template language. Grow extends Jinja2 with a few variables and functions that make building content-rich web sites more convenient.

Variables have no prefix and are part of the global template scope. Functions are prefixed into the g namespace, for example: g.<function name>.


There are several built-in global variables available to templates. Because these variables are not namespaced, take caution not to overwrite their values.


The current content document associated with the current page that's being rendered. See the full documentation for the document API.

{{doc.category}}       # Document's category
{{doc.title}}          # Document's canonical title.
{{doc.titles('nav')}}  # Document's "nav" title.
{{doc.html|safe}}      # Document's rendered Markdown body.
{{doc.foo}}            # Value of the "foo" custom field from the YAML front matter.
{{doc.collection}}     # Document's Collection.
{{doc.collection.foo}} # Value of the "foo" custom field from the collection's `_blueprint.yaml`.


The rendering environment that exists when the page is being built or served.



Refers to the podspec.yaml configuration file and allows you to access pod-wide settings in templates.

{{podspec.title}}         # Pod's title.
{{podspec.project_id}}    # Pod's project ID.




The _ tag is a special function used to tag strings in templates for both translation and message extraction.

# Simple translation.

# A translation with a placeholder.
{{_('Hello, {name}', name='Alice')}}



Lists content documents within a collection and groups them by their $category. Useful for generating navigation and categorized lists of documents.

{% for category, docs in g.categories('pages') %}
    {% for doc in docs %}
    {% endfor %}
{% endfor %}



Returns a Collection object, given a collection path.


g.collections(<optional list of collections>)

Returns a list of all Collection objects in the pod, or lists Collection objects given a list of collection paths.



g.csv(<path to csv>, locale=<identifier>)

Parses a CSV file and returns a list of dictionaries mapping header rows to values for each row. Optionally use keyword arguments to filter results. This can be particularly useful for using a spreadsheet for localization (where rows represent values for different locales).

{% set people = g.csv('/data/people.csv') %}
{% for person in people %}
{% endfor %}


g.date(<DateTime|string>, from=<string>)

Parses a string into a Date object. Uses Python date formatting directives.

# Returns a DateTime given a string and a format.
{{g.date('12/31/2000', from='%m/%d/%Y')}}


g.doc(<document path>, locale=<locale>)

Gets a single content document, given its pod path.

{% set foo = g.doc('/content/pages/index.html') %}

# Returns the fr version of a document.
{{g.doc('/content/pages/index.html', locale='fr')}}


g.docs(<collection>, order_by=<field name>, locale=<locale>)

Searches content documents within a collection.

  {% for doc in g.docs('pages') %}
  {% endfor %}

The documents can also be sorted by multiple fields.

  {% for doc in g.docs('pages', order_by=('dates.published', 'title')) %}
  {% endfor %}


g.json(<path to json file>)

Returns a loaded JSON object, given a JSON file's pod path.


g.locales(<list of locale identifier>)

Returns a list of Locale class given a list of locale identifiers.


Not implemented

Returns an object which can be used to create navigation.


g.static(<file path>)

Returns a StaticFile object corresponding to a static file contained within the pod. <file path> is the full pod path of the static file. You can access the path property of StaticFile.url to retrieve an absolute link to the file's serving path.

It is a best practice to always refer to static files using the g.static tag rather than referring to their URLs directly. This has the benefit of making URL changes easy and Grow will catch broken links to static files at build time.

Prior to using g.static, routes must be configured in the static_dirs property of podspec.yaml.

<img src="{{g.static('/static/example.png').url.path}}">

g.static supports static file localization by way of the localization option of the static_dirs setting in podspec.yaml. If a localized static file exists, it will return the object corresponding to the localized static file. If it doesn't, it will return the object corresponding to the base static file.

# Uses the current document's locale.
{{g.static('/static/example.png', locale=doc.locale)}}

# Uses a hardcoded locale.
{{g.static('/static/example.png', locale='de')}}


g.statics(<pod path>)

Returns a list of StaticFile objects from in a directory within your pod.

{% for static_file in g.statics('/source/images/') %}
  <img src="{{static_file.url.path}}">
{% endfor %}


g.url(<document path>)

Returns the URL object for a document, given a document's pod path. Access the path property of the URL object to retrieve an absolute link to the document.

<a href="{{g.url('/content/pages/index.html').path}}">Home</a>


g.yaml(<path to yaml>)

Returns a parsed yaml object, given a yaml file's pod path. Respects translation tagging.



Formats currency in a localized format. Use's Babel's format_currency.



Formats localized and non-localized dates. Use's Babel's format_date.

{{date_object|date(format='short', locale='ja_JP')}}
{{date_object|date(format="yyyy.MM.dd G 'at' HH:mm:ss zzz")}}


Formats localized and non-localized datetimes. Use's Babel's format_datetime.


Formats decimal in a localized format. Use's Babel's format_decimal.



Recursively applies the gettext translation function to strings within a dictionary.

{% set content = {
  'key': 'String',
  'item_list': [
      'String 1',
      'String 2'
} %}


Converts a dictionary into JSON.



Renders Markdown content into HTML. Use in conjunction with the safe filter to render HTML to a page.



Formats numbers in a localized format. Use's Babel's format_number.



Formats percentages in a localized format. Use's Babel's format_percent.



Generates a relative URL (from the perspective of the current document context) from an absolute URL path.



Randomizes the order of items in a list.



Creates a slug from text.

{{'Hello World'|slug}}


Formats localized and non-localized times. Use's Babel's format_time.