Knowledgebase

Add Custom Structured Data to Invision Community Pages Database

Notice: This article is for providing insight on how to add custom schema markup to "Databases" in Invision Community's Pages application.

There are a few ways to structured data an Invision Community Pages' Database:

  1. Implement Microdata, RDFa, or JSON-LD into a Database template and custom fields,
  2. Create a custom field that allows authors to create customized JSON-LD schema markup,
  3. Use a custom field to implement JSON-LD and map variables to properties.

Basic Implementation: Create a custom field where static JSON-LD structured data can be added

This is the simplest method and will require post authors to create custom JSON-LD structured markup for each post. See Moderate Implementation below for automatically generating structured markup.

  1. In your Invision Community AdminCP, navigate to "Pages" menu item and click the "fields" menu item for your database.
  2. Create a new field and give a title, such as "Schema Markup" or whatever you'd like.
  3. For the "Type", select "Code".
  4. Optional: If you are to generated forum topics for posts in your database, you can include this schema markup to help search engine understand what the topic is and about.
    • You can add <script type="application/jd+json">{value}</script> to the "Topic Format" field box.
  5. Toggle the Accept HTML option.
  6. In the "Display Options" tab, you can give the field any template key name you want as in will not specifically be called to display it on a post page, i.e., visitors will not see it or know it is on the page.
  7. Optional: As with forum topics, you can include JSON-LD structured data in the listings pages of your database. This can be beneficial for search engines to understand the data on the listing pages as their in no schema markup including on these pages by default. Keep in mind that adding this data to each post can affect the performance of your website, which can affect SEO.
    • To add JSON-LD structured data to listing post:
    • Make sure the "show in listing template" option is toggled to on,
    • Listing View Format: Custom,
    • Enter: {{if $formValue}}<script type="application/jd+json">{$value|raw}</script>{{endif}} into the editor box.
  8. Display View section:
    • Make sure the "show in display template" option is toggled to on,
    • Display View Format: Custom,
    • Enter: {{if $formValue}}<script type="application/jd+json">{$value}</script>{{endif}} into the editor box.

Congrats, you can now enter custom JSON-LD structured data into your posts. To learn more about constructing JSON-LD schema, visit Schema.org vocabulary website.

Moderate Implementation: Create a custom field that dynamically calls and maps variables and properties

This is a more advanced method for dynamically embedded values into JSON-LD structured data. This is likely the best way to implement custom data because once setup, markup is added to each post automatically based on custom fields values.

Necessary Variables

VariableTitleDescription
{$record->_title}Record Title
{$record->truncated()|raw}Record Content
{$record->container()->url()}

{$record->container()->_title}
Record Container/Category
{$record->fieldValues()['field_{id#}']}fieldValuesAccessing $values for Text fields or the key (rather than value) for Selectbox and Checkbox Set.
{$record->customFieldDisplayByKey('{Template Key}')}customFieldDisplayByKeyAccessing the formatted input from the Display View Format option.

Note: For fields that will be displayed with any format other than just the value of the field, the ID of those fields are required to populate JSON-LD data with just the field value without the formatting data. The ID will be used with the {$record->fieldValues()['field_{id#}']} variable, replacing {id#} with the ID number, e.g. {$record->fieldValues()['field_123']}.

Note: For Select box and Checkbox Set fields with multiple options, the fieldValues variable will pull the key of the individual option(s). So, it is important to give the options a key that comply with the format of your structured data type from the Schema.org vocabulary. For example, if you are making a "Books" database, and you want to populate the bookFormat property with options from a Checkbox set. In order to have valid schema markup, you have to comply with the Schema.org enumeration members for the enumeration type: BookFormatType, which are limited to: AudiobookFormat, EBook, GraphicNovel, Hardcover, Paperback. enumeration will be the key for your options even if your options value is in another language.

Schema.org Properties and DB Field Types

Schema.org PropertiesDatabase Field TypeNotes
genreSelect box or Checkbox Set
isbnText or Number
inLanguageSelect box or Checkbox Set
authorText
editorText
illustratorText
contributorText
publisherSelect box or Checkbox Set
publisherImprintSelect box or Checkbox Set
isPartOfSelect box or Checkbox SetUsed with the BookSeries schema.org type.
abridgedCheckbox, Radio, or Yes/No
bookFormatSelect box or Checkbox Set
bookEditionText

Basic Instructions

  1. Create a Database,
  2. Add your custom fields, including any of the above that will be mapped to Schema.org Properties.
  3. Create the field that will hold the JSON-LD structured data.
    • "General Options" tab:
      • Title: your choice,
      • Type: Checkbox or Radio,
      • Default Value: 1.
    • "Display options" tab:
      • Template Key: your choice; if you leave this blank, it will be generated automatically when you save the field,
      • List View section: If you want the structured data to be included on listing pages, you can follow and use the steps below:
      • Display View section:
        • Display View Format: Custom,
        • Display: your choice; If you select Under the item content and there are no other fields are there will be a horizontal line with a nothing under it.

Display Custom Format

{{if $formValue}}
<script type="application/ld+json">
{
  "@context": "https://schema.org",
  "@graph": {
    "@type": "Book",
    "name": "{$record->_title}",
    {{if $record->customFieldDisplayByKey('pages', 'display')}}
    "numberOfPages": "{$record->fieldValues()['field_123']}",
    {{endif}}
    {{if $record->customFieldDisplayByKey('genre', 'display')}}
    "genre": "{$record->fieldValues()['field_123']}",
    {{endif}}
    {{if $record->customFieldDisplayByKey('isbn', 'display')}}
    "isbn": "{$record->fieldValues()['field_11']}",
    {{endif}}
    "description": "{$record->truncated()|raw}",
    {{if $record->customFieldDisplayByKey('date', 'display')}}
    "datePublished": "{$record->fieldValues()['field_123']}",
    {{endif}}
    {{if $record->customFieldDisplayByKey('language', 'display')}}
    "inLanguage": {
      "@type": "Language",
      "name": "{$record->fieldValues()['field_123']}"
    },
    {{endif}}
    "url": "{$record->url()}",
    "discussionUrl": "{$record->url()?&tab=comments}",
    {{if $record->customFieldDisplayByKey('author', 'display')}}
    "author": {
      "@type": "Person",
      "name": "{$record->fieldValues()['field_123']}"
    },
   {{endif}}
   {{if $record->customFieldDisplayByKey('editor', 'display')}}
   "editor": {
      "@type": "Person",
      "name": "{$record->fieldValues()['field_123']}"
    },
   {{endif}}
   {{if $record->customFieldDisplayByKey('illustrator', 'display')}}
   "illustrator": {
      "@type": "Person",
      "name": "{$record->fieldValues()['field_123']}"
    },
  {{endif}}
  {{if $record->customFieldDisplayByKey('contributor', 'display')}}
  "contributor": {
      "@type": "Person",
      "name": "{$record->fieldValues()['field_123']}"
    },
  {{endif}}
  {{if $record->record_image}}
  "thumbnail": {
      "@type": "ImageObject",
      "url": "{file="$record->_record_image_thumb" extension="cms_Records"}"
    },
  {{endif}}
  {{if $record->customFieldDisplayByKey('publisher', 'display')}}
    "publisher": {
      "@type": "Organization",
      "name": "{$record->fieldValues()['field_123']}"
    },
  "copyrightHolder": {
      "@type": "Organization",
      "name": "{$record->fieldValues()['field_123']}"
    },
  {{endif}}
  {{if $record->customFieldDisplayByKey('imprint', 'display')}}
  "publisherImprint": {
      "@type": "Organization",
      "name": "{$record->fieldValues()['field_123']}"
    },
  {{endif}}
  {{if $record->customFieldDisplayByKey('series', 'display')}}
  "isPartOf": {
      "@type": "BookSeries",
      "name": "{$record->fieldValues()['field_123']}"
    },
  {{endif}}
  {{if $record->customFieldDisplayByKey('abridged', 'display')}}
  "abridged": "http://schema.org/True",
  {{endif}}
  {{if $record->customFieldDisplayByKey('format', 'display')}}
  "bookFormat": "{$record->fieldValues()['field_123']}",
  {{endif}}
  {{if $record->customFieldDisplayByKey('edition', 'display')}}
 "bookEdition": "{$record->fieldValues()['field_123']}",
 {{endif}}
    "awards": "{$record->fieldValues()['field_123']}"
  }
}
</script>
{{endif}}

Frequently Asked Questions

According to Google, it is recommended to place JSON-LD in the <head>, but it is okay and valid to place it in the <body>.

yes, you can ass property values in other languages, but at this time, Im not sure that the actually JSON-LD language has been translated to other languages. This means that you would have to use the JSON-LD language in English and structure it with values in your language.

Related Articles

One Comment

Leave a Reply

Your email address will not be published. Required fields are marked *


Back to top button