[英]How to pass a concatenated string to HTML using Jekyll include?
I have to make a string of values separated by semicolons and pass this string to a script in HTML include to then parse and output the result.我必须制作一串由分号分隔的值,并将该字符串传递给 HTML 中的脚本,包括然后解析和 output 结果。
My jekyll markdown page:我的杰基尔 markdown 页面:
---
layout: page
title: Our team
permalink: /team
---
{% assign cfhandles=""%}
{% for person in site.data.team-handles %}
{{ cfhandles | append: person.handle }}
{{ cfhandles | append: ";" }}
{% endfor %}
{% include load-ratings.html cfhandles=cfhandles %}
My load-ratings.html:我的 load-ratings.html:
<script>
let url = "https://codeforces.com/api/user.info?handles=";
let handles = "{{ include.cfhandles }}";
console.log(handles);
url = url + handles;
console.log(url);
async function load() {
let obj = await (await fetch(url)).json();
console.log(obj);
for (let cur_user of obj["result"]) {
let cur_handle = cur_user["handle"];
let user_rating = cur_user["rating"];
document.getElementById(cur_handle.toLowerCase()).innerHTML = "Рейтинг: " + user_rating;
}
}
load();
</script>
My team-handles.yml:我的团队 handles.yml:
- handle: bob1
name: Bob
- handle: alice2
name: Alice
When I open the developer console, it shows me that in JS the handles
variable is empty (but it shouldn't be like that).当我打开开发者控制台时,它告诉我在 JS 中
handles
变量是空的(但它不应该是那样的)。 How do I pass the needed string to the file so it shows correctly?如何将所需的字符串传递给文件以使其正确显示?
I already tried using {%- -%} Liquid tags, but it didn't change the result.我已经尝试使用 {%- -%} Liquid 标签,但它并没有改变结果。
Try this:尝试这个:
{% assign cfhandles=""%}
{% for person in site.data.team-handles %}
{% assign cfhandles = cfhandles | append: person.handle | append: ";" %}
{% endfor %}
{% include load-ratings.html cfhandles=cfhandles %}
The code basically assigns the new strings bob1;
代码基本上分配了新字符串
bob1;
and alice2;
和
alice2;
to the existing variable.到现有变量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.