I want to add Google for Jobs to my eleventy (11ty) website. I am using Google Jobposting schema for reference and added the code to json file.

json file:

{
    "layout": "jobpost.njk",
    "tags": "post",
    "jobs": [
      {
        "@context": "http://schema.org",
        "@type": "JobPosting",
        "url": "",
        "title": "",
        "description": "",
        "datePosted": "",
        "validThrough": "",
        "employmentType": "",
        "hiringOrganization": {
          "@type": "Organization",
          "name": "",
          "sameAs": "",
          "logo": ""
        },
        "jobLocation": {
          "@type": "Place",
          "address": {
            "streetAddress": "",
            "addressLocality": ""
          }
        }
      }
    ]
}

Then I added the njk file called google-jobs.njk file from where I reference my json file and also will be used as a template for generating Google Job post listings.

google-jobs.njk file:

<script type="application/ld+json">
  {
    "@context": "http://schema.org",
    "@type": "ItemList",
    "itemListElement": [
      {% for job in jobs %}
        {
          "@type": "JobPosting",
          "url": "{{ url | url | safe }}",
          "datePosted": "{{ date | safe }}",
          "validThrough": "{{ deadline | safe }}",
          "title": "{{ jobTitle | safe }}",
          "description": "{{ content }}",
          "employmentType": "{{ type }}",
          "hiringOrganization": {
            "@type": "Organization",
            "name": "{{ organization | safe }}",
            "sameAs": "{{ website | url | safe }}",
            "logo": "https://example.com{{ image | safe }}"
          },
          "jobLocation": {
            "@type": "Place",
            "address": {
              "@type": "PostalAddress",
              "addressLocality": "{{ location | safe }}"
            }
          }
        }{% if not loop.last %},{% endif %}
      {% endfor %}
    ]
  }
</script>

Lastly, I included the google-jobs.njk template in my layout page where I want to display the job post listings.

<!-- layout.njk -->
<!DOCTYPE html>
<html lang="en">
<head>
  <!-- Other head elements -->
  {% include "google-jobs.njk" %}
</head>
<body>
  <!-- Body content -->
</body>
</html>

The problem

The code is mostly working as intended except for one issue. In the google-jobs.njk file, the value of the url variable is not generating a URL of the current job post. It’s just blank. I’ve tried {{ url | url | safe }}, {{ post.url | safe }}, {{ posts.url | safe }}, {{ job.url | safe }}, and {{ jobs.url | safe }}. None of them fixed the problem.

I’ve tried hardcoding the job post URL to see if it will output something (it did work). So I understood the problem is related to how I set up the data.

Any idea why this happens? I think it’s because I input the variable values incorrectly or have not structured the data correctly.