Skip to content

Commit

Permalink
Remove examples of LanguageCode fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
jmooring authored May 10, 2024
1 parent b608f31 commit fc59e1f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 16 deletions.
6 changes: 3 additions & 3 deletions content/en/methods/page/AllTranslations.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ And this template:
{{ with .AllTranslations }}
<ul>
{{ range . }}
{{ $langName := or .Language.LanguageName .Language.Lang }}
{{ $langCode := or .Language.LanguageCode .Language.Lang }}
<li><a href="{{ .RelPermalink }}" hreflang="{{ $langCode }}">{{ .LinkTitle }} ({{ $langName }})</a></li>
<li>
<a href="{{ .RelPermalink }}" hreflang="{{ .Language.LanguageCode }}">{{ .LinkTitle }} ({{ or .Language.LanguageName .Language.Lang }})</a>
</li>
{{ end }}
</ul>
{{ end }}
Expand Down
6 changes: 3 additions & 3 deletions content/en/methods/page/Translations.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ And this template:
{{ with .Translations }}
<ul>
{{ range . }}
{{ $langName := or .Language.LanguageName .Language.Lang }}
{{ $langCode := or .Language.LanguageCode .Language.Lang }}
<li><a href="{{ .RelPermalink }}" hreflang="{{ $langCode }}">{{ .LinkTitle }} ({{ $langName }})</a></li>
<li>
<a href="{{ .RelPermalink }}" hreflang="{{ .Language.LanguageCode }}">{{ .LinkTitle }} ({{ or .Language.LanguageName .Language.Lang }})</a>
</li>
{{ end }}
</ul>
{{ end }}
Expand Down
10 changes: 2 additions & 8 deletions content/en/methods/site/Language.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,10 @@ Some of the methods above are commonly used in a base template as attributes for

```go-html-template
<html
lang="{{ or site.Language.LanguageCode site.Language.Lang }}"
dir="{{ or site.Language.LanguageDirection `ltr` }}
lang="{{ .Site.Language.LanguageCode }}"
dir="{{ or .Site.Language.LanguageDirection `ltr` }}
>
```

The example above uses the global [`site`] function instead of accessing the `Site` object via the `.Site` notation.

Also note that each attribute has a fallback value assigned via the [`or`] operator.

[details]: /methods/page/language/
[RFC 5646]: https://datatracker.ietf.org/doc/html/rfc5646
[`or`]: /functions/go-template/or/
[`site`]: /functions/global/site/
4 changes: 2 additions & 2 deletions content/en/templates/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,10 @@ Remember that the piped value becomes the final argument to the function or meth
You can split a template action over two or more lines. For example, these are equivalent:

```go-html-template
{{ $v := or .Site.Language.LanguageCode .Site.Language.Lang }}
{{ $v := or .Site.Language.LanguageName .Site.Language.Lang }}
{{ $v := or
.Site.Language.LanguageCode
.Site.Language.LanguageName
.Site.Language.Lang
}}
```
Expand Down

0 comments on commit fc59e1f

Please sign in to comment.