Как я могу изменить цель forloop с множеством разных файлов данных в заголовке JSON + LD, включая

Проблема

У меня есть один элемент JSON+LD в голове для анализа страниц статей типа QA (вопросы и ответы). Цель forloop меняется на каждой странице темы. Я не могу понять, как изменить цель forloop, чтобы она соответствовала файлу данных для каждой страницы, чтобы он мог перебирать данные в универсальном скрипте json+ld для статей с контролем качества (вопросы и ответы).

  1. Если вы находитесь на странице о преступлении, связанном с наркотиками, перетащите цикл файла Drug.yml в универсальный файл json+LD в <head>.
  2. Если на странице уголовного преступления, перетащите цикл файлаcrime.yml в универсальный json+LD в <head>.

Что я пробовал

{
    "@type": "ItemList",
    "itemListElement": [
  {% for data in site.data.faq.{{page.pagefaq}} %}
      {
        "@type": "Question",
        "name": "{{data.question}}",
        "url": "{{page.url}}/#{{data.id}}",
        "position": "{{ forloop.index }}",
        "acceptedAnswer": {
          "@type": "Answer",
          "text": "{{ data.answer}}"
        }
     }{% if forloop.last %}{% else %},{% endif %}
  {% endfor %}],

Теперь я понимаю, что не могу вставить переднюю переменную в цикл for. Тем не менее, это имя файла данных меняется на каждой странице для отображения JSON+LD в файле <head>.

Цикл for работает на странице, потому что цель forloop yml жестко запрограммирована. На обложке каждой страницы у меня есть: pagefaq:xxxxx. Итак, я должен каким-то образом указать циклу JSON+LD, какой файл данных заполнять.

Пример YML-файла

drug.yml

- id: q1
  question: "What is Florida's Marijuana Possesion Law?"
  answer: "In Florida, possession of marijuana without a prescription is a criminal offense. Individuals found to have less than 20 grams on their person may be charged with a misdemeanor, while those found with 20 grams or more of marijuana may be charged with a felony. Medical patients are advised to always have their card and their prescription on them when transporting their medication."
- id: q2
  question: "What is Florida's Oxycodone possesion law?"
  answer: "A prescription painkiller, oxycodone can be found in both OxyContin and Percocet. Individuals found to have less than 7 grams of oxycodone on their person without a prescription may be charged with a third-degree felony. Individuals found to have 7 grams or more may be charged with trafficking."
- id: q3
  question: "What is Florida's Drug Possesion Law?"
  answer: "Drug possession laws aim to limit the possession and personal use of illegal substances. These controlled substances include both Schedule 1 drugs like heroin, LSD, meth, and ecstasy and even prescription drugs like oxycodone and fentanyl.


It’s important to note that marijuana, though allowed for medical use, is still classified as a Schedule 1 drug at the federal level and considered an illegal substance. In Florida, Amendment 2, which was passed in November 2016, allows for the use and cultivation of medical marijuana for qualifying patients. The law does not allow everyone carte blanche access to marijuana. Rather, it requires that patients apply for a medical marijuana card and imposes purchasing and possession limits to ensure that medical marijuana is not abused.


Outside of medical marijuana, one must have a prescription. If you are in possession of marijuana, you can be charged with a misdemeanor or even a felony, depending on the amount of marijuana you have in your possession."

person Denver Prophit Jr.    schedule 21.09.2019    source источник


Ответы (1)


Ответ исходит от Дэвида Жакеля Может ли цикл жидкости for содержать переменную страницы в Jekyll?


Вы можете использовать обозначение в скобках следующим образом:

{% for data in site.data.faq.[page.pagefaq] %}
person Denver Prophit Jr.    schedule 23.09.2019