[英]How to pass a concatenated string to HTML using Jekyll include?
我必須制作一串由分號分隔的值,並將該字符串傳遞給 HTML 中的腳本,包括然后解析和 output 結果。
我的傑基爾 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 %}
我的 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>
我的團隊 handles.yml:
- handle: bob1
name: Bob
- handle: alice2
name: Alice
當我打開開發者控制台時,它告訴我在 JS 中handles
變量是空的(但它不應該是那樣的)。 如何將所需的字符串傳遞給文件以使其正確顯示?
我已經嘗試使用 {%- -%} Liquid 標簽,但它並沒有改變結果。
嘗試這個:
{% assign cfhandles=""%}
{% for person in site.data.team-handles %}
{% assign cfhandles = cfhandles | append: person.handle | append: ";" %}
{% endfor %}
{% include load-ratings.html cfhandles=cfhandles %}
代碼基本上分配了新字符串bob1;
和alice2;
到現有變量。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.