JSON-LD in Wagtail

358 views
Skip to first unread message

Mark Churchill

unread,
Dec 9, 2016, 7:05:10 AM12/9/16
to Wagtail support
Does anyone have experience using Wagtail fields to generate JSON-LD (i.e. linked data markup using schema.org?)

Or know of any Wagtail-powered sites doing this? I looked at the landmark RCA.ac.uk site but couldn't find any json+ld data blocks

Eric Todd

unread,
Dec 27, 2016, 7:18:12 PM12/27/16
to Wagtail support
Hi Mark,

I did it for a news site that I work on. I didn't do anything fancy, just added the json-ld to the template. That looks something like this:

  <script type="application/ld+json">
  {
    "@context": "http://schema.org",
    "@type": "NewsArticle",
    "mainEntityOfPage": {
      "@type": "WebPage",
      "@id": "{{ self.full_url }}"
    },
    "headline": "{{ self.title }}",
    "image": {% image self.image width-696 as json_img %} {
      "@type": "ImageObject",
      "url": "{{ json_img.url }}",
      "height": {{ json_img.height }},
      "width": {{ json_img.width }}
    },
    "datePublished": "{{ self.date|date:'c' }}",
    "dateModified": "{{ self.latest_revision_created_at|date:'c' }}",
    "author": {
      "@type": "Person",
      "name": "{{ self.author }}"
    },
  "description": "{{ self.description }}"
</script>

Does that help? Or did I miss the point of your question?

-eric

Mark Churchill

unread,
Dec 29, 2016, 5:26:43 AM12/29/16
to Wagtail support
Thanks Eric. Yes that does answer the question!

So you opted to code it in directly – fair enough. I was thinking I might go that route too… and will do if I don't find anything else. But since some CMSs have plugins that generate this kind of output directly I thought I'd ask around, see if anyone knew of anything…

Tom Dyson

unread,
Dec 29, 2016, 6:44:03 AM12/29/16
to wag...@googlegroups.com
Hi Mark

Does this help?


It's by Tim Heap, one of Wagtail's core contributors. 

Yours

Tom

--


You received this message because you are subscribed to the Google Groups "Wagtail support" group.


To unsubscribe from this group and stop receiving emails from it, send an email to wagtail+u...@googlegroups.com.


To post to this group, send email to wag...@googlegroups.com.


Visit this group at https://groups.google.com/group/wagtail.


To view this discussion on the web, visit https://groups.google.com/d/msgid/wagtail/31893eb3-da5e-489c-9729-196cd7b760c7%40googlegroups.com.


For more options, visit https://groups.google.com/d/optout.


Mark Churchill

unread,
Jan 3, 2017, 10:33:02 AM1/3/17
to Wagtail support
Aha! Exactly that. 

Brilliant!

Thanks a lot, Tom :)
Reply all
Reply to author
Forward
0 new messages