Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Stuart Paterson 34 posts 175 karma points
    Mar 12, 2020 @ 15:30
    Stuart Paterson
    0

    Generate Schema Markup for Nested Content

    Hi there,

    I've started creating a new model and controller to generate FAQ schema data for each FAQ item on a given page.

    I'd like to render this in a Schema data partial in the format below, however the part i'm struggling with is how to generate a question & answer set in JSON for each nested content item/FAQ.

    <script type="application/ld+json">
    {
    "@@context": "https://schema.org",
    "@@type": "FAQPage",
    "mainEntity": [{
    "@@type": "Question",
    "name": "@Model",
    "acceptedAnswer": {
    "@@type": "Answer",
    "text": "@Model.answerText"
    }
    }]
    }
    

    Anybody done this before? or any pointers, packages or reference sites I could take a look at?

    Cheers Stuart

  • Alex Skrypnyk 5772 posts 21986 karma points MVP 4x admin c-trib
    Apr 29, 2020 @ 19:57
    Alex Skrypnyk
    101

    Hi Stuart,

    Razor is not for structured data markup, Razor is for rendering HTML. Razor is very bad in rendering JSON, javascript, or structured data.

    That's why I don't recommend you to render the structured data with Razor, I think there are 2 little bit better ways of rendering the Structured data:

    1) use Schema.NET library - https://www.nuget.org/packages/Schema.NET - Schema.org objects turned into strongly typed C# POCO classes for use in .NET. All classes can be serialized into JSON/JSON-LD and XML, typically used to represent structured data in the head section of the HTML page.

    2) use Structured Data Markup Helper to render Structured data and then store rendered data in the CMS in the text field - https://www.google.com/webmasters/markup-helper/u/0/

    And of course, these 2 options are not optimal for things like breadcrumb - in this case, probably makes sense to use Microdata format instead of ld+json

    Please, share how did you go with it and your thoughts.

    Thanks,

    Alex

  • Stuart Paterson 34 posts 175 karma points
    Jun 23, 2020 @ 10:18
    Stuart Paterson
    1

    Hi Alex,

    I marked your answer as the solution to this, having looked at the link for the Schema.Net package it looks perfect what we were trying to do so I believe it is the approach we want to take.

    I just wanted to tag a note on this post though to say that having tried to install the Schema.Net package through package manager in Visual Studio, it actually ripped out Umbraco 7.10.5 from my local dev environment and after the Schema.Net package installed, it then proceeded to try and install Umbraco 7.15

    Didn't see anything on the Schema.Net git page which pre-warned about this unless I've missed it so wanted to flag it on this post, just in case.

    Cheers Stuart

  • Alex Skrypnyk 5772 posts 21986 karma points MVP 4x admin c-trib
    Jun 24, 2020 @ 10:12
    Alex Skrypnyk
    0

    Hi Stuart

    Thanks for letting us know about this problem. Maybe you have to use -IgnoreDependencies? But I'm not sure why nuget do it like that.

    Install-Package Schema.NET  -IgnoreDependencies
    

    Thanks,

    Alex

  • David Peck 589 posts 1558 karma points c-trib
    Apr 29, 2020 @ 22:04
    David Peck
    1

    I used MXTires.Microdata very successfully, but there's not harm in just using a JObject in my book.

  • Stuart Paterson 34 posts 175 karma points
    May 01, 2020 @ 12:28
    Stuart Paterson
    0

    Alex, David thanks a lot for your comments and pointing me in the right direction.

    I'll give those a look over and drop a note back on here with the final solution just in case anybody else is looking for it. Creating structured data for our standard product pages seems simple enough as there's only one block of JSON per page, it's generating the data for those nested content FAQ's that I couldn't get my head around :)

    Cheers, Stuart

Please Sign in or register to post replies

Write your reply to:

Draft