jekyll - 如何使用{{a variable [inside] a variable}}?
问题描述
我是 Jekyll 和 Liquid 的新手,我正在尝试做一些小事情,但我不知道如何让它发挥作用。
基本上:
this.works[well]
(我认为)
但:
this.does.[not].work
this.does[not]work
[this].does.not.work
[this]does.not.work
所以这就是我的问题:如何在“变量路径”中插入单个变量?
基本上我想调用来自不同语言的文本字符串,它们现在位于我的 _data 文件夹中。我想做的是类似于:
_data/en.yml:
hello: ‘Hello!’
页面前端:
lang: en
字符串必须出现的位置:
{{ site.data[page.lang]hello }}
任何正确的方法来做到这一点?
知道我会有几十个这样的字符串,所以它应该尽可能紧凑。
解决方案
好的,我想通了,它是:
site.data[page.lang].hello
我有一个后续问题,我也在包含中传递了这些字符串。
这不起作用,并给出语法错误:
{% include box.html text=site.data[page.lang].hello %}
所以我必须做这样的事情:
{% assign hello=site.data[page.lang].hello %}
{% include box.html text=hello %}
这非常冗长和愚蠢:我最终写了 3 次(!)我的变量名,并创建了很多重复的变量。
任何人都知道如何在不写我的字符串名称 3 次的情况下编写?谢谢!!
(更愚蠢的是,您可以在 include 的第一部分使用带有 [] 的变量,但不能在第二部分使用?
{% include site.data[page.lang].box text=hello %}
例如可以工作……)
推荐阅读
- rest - 我可以使用 REST API 在 Discord 的“Server Insights”中获取为我的服务器提供的数据吗?
- python-3.x - 使用 CLI/Python API 导出 Google AutoML 模型
- javascript - 如何检查字符串/变量是否以移动区号开头?
- javascript - React - TypeError:无法读取 null 的属性“toFixed”
- docusignapi - DocuSign.eSign.Client.ApiException:未处理的响应类型
- file - Jmeter 测试:如何生成许多独特的文件?
- date - Power BI - 检查事件是否在相关表中的两个日期之间
- swift - 我的代码没有运行。此代码是著名的“FizzBuzz”问题
- windows - ffmpeg 和 ffprobe 嵌套延迟扩展变量
- c++ - const 元组到 const 元组?