urls.RelLangURL

此函數可用於單語與多語配置。函數返回的 URL 取決於以下因素:

  • 輸入是否以斜線開頭
  • 網站配置中的 baseURL
  • 語言前綴(如果有)

以下範例中,專案為多語言,包含英文 (en) 和西班牙文 (es) 內容。返回值來自英文網站。

輸入不以斜線開頭

如果輸入不以斜線開頭,則結果 URL 將相對於網站配置中的 baseURL

baseURL = https://example.org/ 時:

{{ relLangURL "" }}                        → /en/
{{ relLangURL "articles" }}                → /en/articles
{{ relLangURL "style.css" }}               → /en/style.css
{{ relLangURL "https://example.org/foo" }} → /en/foo

baseURL = https://example.org/docs/ 時:

{{ relLangURL "" }}                             → /docs/en/
{{ relLangURL "articles" }}                     → /docs/en/articles
{{ relLangURL "style.css" }}                    → /docs/en/style.css
{{ relLangURL "https://example.org/docs/foo" }} → /docs/en/foo

輸入以斜線開頭

如果輸入以斜線開頭,則結果 URL 將相對於 baseURL 的協議與主機部分。

baseURL = https://example.org/ 時:

{{ relLangURL "/" }}          → /en/
{{ relLangURL "/articles" }}  → /en/articles
{{ relLangURL "/style.css" }} → /en/style.css

baseURL = https://example.org/docs/ 時:

{{ relLangURL "/" }}          → /en/
{{ relLangURL "/articles" }}  → /en/articles
{{ relLangURL "/style.css" }} → /en/style.css