TTWeb Liquid 1. Permalinks and IDs

General Format

{{ <page|path|model-file-name> | permalink: [model-dir:<model-directory-name>][, locale:<locale>] }}

In order to support the TTWeb custom data and i18n implementations, the standard jekyll permalink won’t work. Instead you should use the custom permalink filter e.g. {{ <thingtolinkto> | permalink }}. This will ensure that the page or model you want to link to will always generate the correct URL when people change the URL slugs. The <thingtolinkto> should be an ID OR the page object itself. This will either be the page’s file path in the project or the model ID, which is the name of the JSON file.

Get URL to a page by ID

{% raw %}

{{ '_pages/about' | permalink }}

Get URL for a page object

For instance if you’re looping through a list of pages, or want to check the current URL

{% for page in site.pages %}
  <a href="{{ page | permalink }}">
{% endfor %}

or

{% assign current_url = page | permalink %}

Get URL for a content model instance page

In this case we’re generating URLs for content model instances assuming that the model type is configured for page_gen. For example, if page_gen is set up for the “rooms” model, we would set up the permalink as below making sure that value for model_dir matches the value of dir in the page_gen configuration

{{ 'rooms1' | permalink: model_dir: 'rooms' }}

or

{% for room in site.data._models.rooms %}
  {{ room.id | permalink: model_dir: 'rooms' }}
{% endfor %}

I18n usage

When a page is rendered, the URL generated from the permalink filter will be for the current langauge. If you want to generate a link in a specific language (e.g. link to the current page in another langauge), you can set the locale in the filter:

{{ page | permalink: locale: 'en' }}

or

{% for lang in site.languages %}
  <a href="{{ page | permalink: locale: lang }}">View this page in {% t 'header.language_name', lang %}</a>
{% endfor %}