动态变量Jekyll Liquid

编程入门 行业动态 更新时间:2024-10-23 09:30:44
本文介绍了动态变量Jekyll Liquid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想在我的jekyll +液体安装中使用动态变量. 我想使用动态变量动态访问_config.yml文件 名称.

I would like to use dynamic variables for my jekyll + liquid installation. I want to dynamically access the _config.yml file using the dynamic variable names.

最好用一个例子来解释:

It is best explained with an example:

页面:

--- layout: default title: title_homepage ---

默认布局:

{{ site.locales[site.default_locale].page.title }}

_config.yml:

default_locale: "en" locales: en: title_homepage: "This is my homepage title!" pirate: title_homepage: "Yaaawwwr. Homepage title."

那么如何使用动态变量名访问_config.yml?

So how can I access the _config.yml with a dynamic variable name?

推荐答案

您要提取的标题来自站点配置.不是页面本身.您需要做的就是将默认布局"列表中的调用更改为此:

The title that you want to pull is form the site config. Not the page itself. All you need to do is change the call in your Default Layout listing to this:

{{ site.locales[site.default_locale].title_homepage }}

设置default_locale: "en"时,输出将为这是我的首页标题!".当您将_config.yml文件更新为default_locale: "pirate"时,输出将为"Yaaawwwr.Homepage title".我已经在Jekyll 0.11.2上对其进行了测试,它可以按预期工作.

When you set default_locale: "en" the output will be "This is my homepage title!". When you update the _config.yml file to default_locale: "pirate", the output will be "Yaaawwwr. Homepage title." I've tested this on Jekyll 0.11.2 and it works as expected.

更多推荐

动态变量Jekyll Liquid

本文发布于:2023-11-28 07:26:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1641468.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:变量   动态   Liquid   Jekyll

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!