urls.RelLangURL
语法
urls.RelLangURL INPUT
返回值
string
别名
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