Skip to content

Instantly share code, notes, and snippets.

@ankedsgn
Created December 17, 2018 13:41
Show Gist options
  • Save ankedsgn/9724390249726d642f6447da9da54f8f to your computer and use it in GitHub Desktop.
Save ankedsgn/9724390249726d642f6447da9da54f8f to your computer and use it in GitHub Desktop.
Bolt + Twig - guess language for 404 page
{#
Create a user friendly 404 page that guesses the broken link by looking at the language attribute, and serving the appropriate language
#}
{# Special 404 case, no locales present: check for language #}
{% set language = getlanguage()|default(app.request.pathInfo|split("/")[1])|default('nl') %}
{% if language == 'en' %}
{% set record = record.endata|json_decode %}
{% endif %}
{# {{dump(locales)}} #}
<h1 lang="{{language}}">{{ record.title }}</h1>
{% if record.introduction is defined and record.introduction is not empty %}
<div lang="{{language}}" class="introduction">
{{ record.introduction|raw }}
</div>
{% endif %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment