Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add partial template for hreflang annotations #19

Merged
merged 2 commits into from
Feb 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions README.md
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,22 @@ Copy the template file [langswitcher.html.twig](templates/partials/langswitcher.

You can now edit the override and tweak it however you prefer.

## Usage of the `hreflang` partial

A second template is available for `hreflang` annotations in the header of the page. In order to emit language annotations for the available languages of a page you need to add the corrsponding Twig partial template into the `<head>` section of your page, which can typically be found in `base.html.twig`:

```
{% include 'partials/langswitcher.hreflang.html.twig' %}
```

This will generate something like:

```
<link rel="alternate" href="http://example.com/en" hreflang="en" />
<link rel="alternate" href="http://example.com/de" hreflang="de" />
<link rel="alternate" href="http://example.com/zh-cn" hreflang="zh-cn" />
```

# Updating

As development for the LangSwitcher plugin continues, new versions may become available that add additional features and functionality, improve compatibility with newer Grav releases, and generally provide a better user experience. Updating LangSwitcher is easy, and can be done through Grav's GPM system, as well as manually.
Expand Down
9 changes: 9 additions & 0 deletions templates/partials/langswitcher.hreflang.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{% set langobj = grav['language'] %}
{% for key in langswitcher.languages %}
{% if key == langswitcher.current %}
{% set lang_url = page.url %}
{% else %}
{% set lang_url = base_url_simple ~ langobj.getLanguageURLPrefix(key)~langswitcher.page_route ?: '/' %}
{% endif %}
<link rel="alternate" hreflang="{{ key }}" href="{{ lang_url ~ uri.params }}" />
{% endfor %}