title: How can I change the forloop target with many different data files in a JSON+LD head include
body: <h1>Problem</h1>
  
  <p>I have one <strong>JSON+LD</strong> include in the head to parse QA (Questions &amp; Answers) type article pages. The forloop target changes on every topic page. I cannot figure out how to variable the forloop target to match the data file for each page so it can loop through the data in the universal json+ld script for articles with QA ( Questions &amp; Answers).</p>
  
  <ol>
  <li>If on drug offense page, pull the drug.yml file loop into the universal json+LD into <code>&lt;head&gt;</code>.</li>
  <li>If on criminal offense page, pull the crime.yml file loop into the universal json+LD into <code>&lt;head&gt;</code>.</li>
  </ol>
  
  <h1>What I've Tried</h1>
  
  <pre><code>{
      "@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 %}],
  </code></pre>
  
  <p>I realize now that I cannot insert a frontmatter variable in the forloop. Yet, that data file name changes on each page to render the JSON+LD in the <code>&lt;head&gt;</code>.</p>
  
  <p>The forloop works on the page because the forloop target yml is hardcoded. On each page frontmatter, I have: <code>pagefaq:xxxxx</code>. So, I must somehow be able to tell the JSON+LD loop which datafile to populate.</p>
  
  <h1>Sample YML File</h1>
  
  <p><code>drug.yml</code></p>
  
  <pre><code>- 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."
  </code></pre>