getgrav / getgrav/grav-plugin-langswitcher

langswitcher.hreflang.html.twig displays incorrect urls when Grav is configured to generate absolute urls

Open
#77 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
PHP
Stars
31
Forks
25
PR merge metrics
No merged PRs in 30d

Description

I have configure Grav to generate absolute urls (`absolute_urls: true`). In this case the template langswitcher.hreflang.html.twig displays incorrect urls with duplicate base (e.g. http://www.example.comhttp://www.example.com/en/example).

As a solution, `uri.base` should be added to the url only if `absolute_urls` is set to false:

```
{% if config.system.absolute_urls %}
{% set href_url = lang_url ~ uri.params ~ (uri.query|length > 1 ? '?' ~ uri.query) %}
{% else %}
{% set href_url = uri.base ~ lang_url ~ uri.params ~ (uri.query|length > 1 ? '?' ~ uri.query) %}
{% endif %}
```

Furthermore there is an error in line 12: `config.languages.include_default_lang` doesn't exist and should be replaced by `config.system.languages.include_default_lang`.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with langswitcher.hreflang.html.twig, focusing on the href construction and the include_default_lang reference described in the issue. Verify generated links with absolute_urls enabled and disabled, and confirm the language setting is read from the stated system configuration path; done means no duplicate base URL and correct language links in both modes.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
localization
Issue type
Bug
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.