Set JSON-LD information in Aptuitiv Twig templates.

Aptuitiv includes JSON-LD information for every page of the website. Most of the default information comes from the Company Information and Structured Data Settings for the website.

The JSON-LD information is automatically output where the head information is output in your templates with {{ _page.head() }}.

While a lot of the core information is output automatically, you can customize the information programmatically in the Twig templates using the _page.jsonLd object.

The jsonLd key is case insensitive, so you can use _page.jsonLd or _page.jsonld. You could use _page.JSONLD if you wanted. We recommend the lowercase version.

To access most information, you access a specific data type with the _page.jsonld object. The supported entities are:

  • event
  • entity
  • organization
  • person
  • webpage
  • website

For example, to access the organization information, you would use _page.jsonld.organization

Publisher types

The publisher types are:

  • organization
  • person

You can access them using the following objects:

  • entity
  • organization
  • person

They all provide the same information. You can use the generic entity to set the information. We recommend using organization or person because they are more explicit. However, the entity value is useful if you are developing a website and you won't know what publisher type will be set.

{% do _page.jsonld.entity.setName('Company Name') %}
{# That is the same as: #}
{% do _page.jsonld.organization.setName('Company Name') %}

You can change the publisher type in your template. We recommend using the Structured Data Settings page in the administration to do this, but you can do it in code.

{# Set the entity for the website to be "Person" #}
{% do _page.jsonLd.setEntityIsPerson() %}

{# Set the entity for the website to be "Organization" #}
{% do _page.jsonLd.setEntityIsOrganization() %}

Shorten your code

If you are doing a lot of updates to the JSON-LD data in your code, then you prevent a lot of duplicate typing by setting the data object to a variable.

{# 
Save the organization to a variable. 
This means we don't have to type "_page.jsonld.organization" for each method call. 
#}
{% set org = _page.jsonld.organization %}

{# Now our calls are shorter #}
{% do org.setName('Company Name') %}
{% do org.setTelephone('111-333-3333') %}

Create custom data objects

While there are shortcut methods to adding common data, sometimes you need to create your own data object and add it to an entity.

You would use _page.jsonld.create() to do this.

For example, to add an image to an organization, you can do this:

{% set image = _page.jsonld.create('image') %}
{% set image.url = '/path/to/image.jpg' %}
{% set image.caption = 'Image caption' %}
{% set _page.jsonld.organization.image = image %}

The signature for the create() method is:

create(objectType)

You would pass the entity type as a lowercase value. See https://schema.org/docs/full.html for the full list of entity types.

Setting data on an entity

Some of the entities have built-in methods for setting common data types. However, if you don't find a method for your data type, you can still add the data in a few different ways.

There is a "magic" setSOMETHING() method that will set the "SOMETHING" value on the entity.

For example, you can use setEmail() to set the email address even though it's not a built-in method.

{% do _page.jsonld.organization.setEmail('company@domain.com') %}

You can also just set the data type on the entity object.

For example, this is also how you can set the email on the organization.

{% set _page.jsonld.organization.email = 'company@domain.com' %}

The value type can be a string, a number, an array of data, and object of information, or an Item object.

{# string example #}
{% set _page.jsonld.organization.email = 'company@domain.com' %}
{% do _page.jsonld.organization.setEmail('company@domain.com') %}

{# array example. This sets multiple values for the data type. #}
{% do _page.jsonld.organization.setOpeningHoursSpecification([
        {
            dayOfWeek: ['Monday', "Tuesday", "Wednesday", "Thursday", "Friday"],
            opens: '08:00',
            closes: '17:00'
        },
        {
            dayOfWeek: ["Saturday"],
            opens: '10:00',
            closes: '13:00'
        }
]) %}

{% set _page.jsonld.organization.openingHoursSpecification = [
        {
            dayOfWeek: ['Monday', "Tuesday", "Thursday", "Friday"],
            opens: '08:00',
            closes: '17:00'
        },
        {
            dayOfWeek: ["Sunday"],
            opens: '10:00',
            closes: '13:00'
        }
] %}

{# Object of information example #}
{% do _page.jsonld.organization.setAddress({
    streetAddress: '123 Main St',
    addressLocality: 'Springfield',
    addressRegion: 'IL',
    postalCode: '12345'
}) %}

{% set _page.jsonld.organization.address = {
    streetAddress: '123 Main St',
    addressLocality: 'Springfield',
    addressRegion: 'IL',
    postalCode: '98765'
} %}

{# Item object example #}
{% set address = _page.jsonld.create('address') %}
{% set address.streetAddress = '123 Main St' %}
{% set address.addressLocality = 'Springfield' %}
{% set address.addressRegion = 'IL' %}
{% do address.setPostalCode('12345') %}
{% do _page.jsonld.organization.setAddress(address) %}

{% set _page.jsonld.organization.address = address %}

Setting multiple values

Some data types can have multiple values. For example, you may have multiple email addresses, phone numbers, or addresses.

There are two ways to add multiple values.

First, you can add all values at once as an array of values. For example, to set opening hours for different days you could do something like this:

{% set _page.jsonld.organization.openingHoursSpecification = [
        {
            dayOfWeek: ['Monday', "Tuesday", "Thursday", "Friday"],
            opens: '08:00',
            closes: '17:00'
        },
        {
            dayOfWeek: ["Sunday"],
            opens: '10:00',
            closes: '13:00'
        }
] %}

Or, you can set multiple email addresses:

{% do _page.jsonld.organization.email = ['email1@domain.com', 'email2@domain.com'] %}

The other method is to use the "magic" addSOMETHING() method. This is the same concept as the setSOMETHING() method discussed above, except that this will set the data to be an array of values. However, if only one value is set then it will not output as a set of items. (For example, if you use addImage() but only one image is set, then a single image will be output instead of an array of images.)

{# string example #}
{% do _page.jsonld.organization.addEmail('company@domain.com') %}
{% do _page.jsonld.organization.addEmail('altemail@domain.com') %}

{# array example #}
{% do _page.jsonld.organization.addEmail(['company@domain.com', 'altemail@domain.com']) %}

{% do _page.jsonld.organization.addOpeningHoursSpecification([
        {
            dayOfWeek: ['Monday', "Tuesday", "Wednesday", "Thursday", "Friday"],
            opens: '08:00',
            closes: '17:00'
        },
        {
            dayOfWeek: ["Saturday"],
            opens: '10:00',
            closes: '13:00'
        }
]) %}

{# object example  #}
{% do _page.jsonld.organization.addOpeningHoursSpecification({
            dayOfWeek: ['Monday', "Tuesday", "Wednesday", "Thursday", "Friday"],
            opens: '08:00',
            closes: '17:00'
}) %}
{% do _page.jsonld.organization.addOpeningHoursSpecification({
            dayOfWeek: ["Saturday"],
            opens: '10:00',
            closes: '13:00'
        }
}) %}

{% do _page.jsonld.organization.addAddress({
    streetAddress: '123 Main St',
    addressLocality: 'Springfield',
    addressRegion: 'IL',
    postalCode: '98765'
}) %}
{% do _page.jsonld.organization.addAddress({
    streetAddress: '3 Another St',
    addressLocality: 'Orlando',
    addressRegion: 'FL',
    postalCode: '12345'
}) %}

{# Item object example #}
{% set address = _page.jsonld.create('address') %}
{% set address.streetAddress = '123 Main St' %}
{% set address.addressLocality = 'Springfield' %}
{% set address.addressRegion = 'IL' %}
{% do address.setPostalCode('98765') %}
{% do _page.jsonld.organization.addAddress(address) %}

Website Data

The WebSite data describes the entire website. See https://schema.org/WebSite for more information.

These are the built-in methods on the website object.

disableSearch()

Removes the "potentialAction" value from the Website data so that the search functionality is not promoted.

{% do _page.jsonld.website.disableSearch() %}

setId

Sets the ID for the WebSite object.

This is done automatically by the Aptuitiv platform when a page is rendered.

{% do _page.jsonld.website.setId('idValue') %}

setName

Set the website name.

This is done automatically by the Aptuitiv platform when a page is rendered.

{% do _page.jsonld.website.setName('Website name') %}

setPublisher

Sets the id of the entity that published the WebSite.

This is done automatically by the Aptuitiv platform when a page is rendered.

{% do _page.jsonld.website.setPublisher(publisherObject) %}

setSearchAction

Set the search URL and search action on the WebSite data.

This is done automatically by the Aptuitiv platform when a page is rendered if the search is enabled.

{% do _page.jsonld.website.setSearchAction('/search') %}

setSearchUrl

This is an alias to setSearchAction.

{% do _page.jsonld.website.setSearchUrl('/search') %}

setType

Set the WebSite type.

This is done automatically by the Aptuitiv platform when a page is rendered.

{% do _page.jsonld.website.setType('WebSite') %}

setUrl

Set the URL for the WebSite object.

This is done automatically by the Aptuitiv platform when a page is rendered.

{% do _page.jsonld.website.setUrl('https://www.yourwebsite.com/#website') %}

WebPage data

The WebPage data describes a single page on the website.

If the page is not a basic web page, then the primary item isPartOf the WebPage.

WebPage isPartOf WebSite, whose publisher is Organization or Person.

These are the built-in methods on the website object.

setDateModified

Sets the date that the webpage was last modified.

This is done automatically by the Aptuitiv platform when a page is rendered.

{# The passed value needs to be a timestamp #}
{% do _page.jsonld.webpage.setDateModified(1734125683) %}

setDescription

Set the description for the WebPage. This is the same as the SEO meta description value.

This is done automatically by the Aptuitiv platform when a page is rendered.

{% do _page.jsonld.webpage.setDescription('Page description here') %}

setId

Sets the ID for the WebPage object.

This is done automatically by the Aptuitiv platform when a page is rendered.

{% do _page.jsonld.webpage.setId('https://www.mysite.com/url/#webpage') %}

setName

Set the WebPage name. This is the same as the page SEO title.

This is done automatically by the Aptuitiv platform when a page is rendered.

{% do _page.jsonld.webpage.setName('Page title here') %}

setParent

Sets the parent object that this WebPage is part of.

This is done automatically by the Aptuitiv platform when a page is rendered. The WebSite object is set as the parent.

{% do _page.jsonld.webpage.setParent(parentObject) %}

setTitle

This is an alias to setName().

{% do _page.jsonld.webpage.setTitle('Page title here') %}

setType

Set the WebPage type.

This is done automatically by the Aptuitiv platform when a page is rendered.

{% do _page.jsonld.website.setType('WebPage') %}

Organization and Person data

Organization or Person is the publisher type for the WebSite. The publisher type can be either "Organization" or "Person".

The publisher object is automatically set as the publisher for the WebSite when the page is rendered.

While you can use entity, organization, or person for the publisher type, we're going to use organization in our examples as it's the most common. If you are developing a reusable theme then you may want to use entity.

These are the built-in methods on the publisher object.

addAddress

Add an address. See https://schema.org/PostalAddress for more information.

This allows you to set multiple addresses when you call it multiple times.

You can either pass the address data as parameters, as an array of information, or as an Item object.

The method signature is: 

addAddress(streetAddress, addressLocality, addressRegion, postalCode, addressCountry)

addAddress(addressDataObject)

addAddress(addressItemObject)

{# Pass the individual image data values #}
{% do _page.jsonld.organization.addAddress('3 Main St', 'Orlando', 'FL', '12345', 'US') %}

{# Pass an object of information #}
{% do _page.jsonld.organization.addAddress({
    streetAddress: '3 Main St',
    addressLocality: 'Orlando',
    addressRegion: 'FL',
    postalCode: '12345',
    addressCountry: 'US'
}) %}

{# Create an Item object #}
{% set addr = _page.jsonld.create('address') %}
{% set addr.streetAddress = '123 Main St' %}
{% set addr.addressLocality = 'Springfield' %}
{% set addr.addressRegion = 'IL' %}
{% do addr.setPostalCode('62701') %}
{% do _page.jsonld.organization.addAddress(addr) %}

addImage

Add one or more images and sets them under the image data key. See https://schema.org/image for more information.

This allows you to set multiple images when you call it multiple times.

You can either pass the image data as parameters or you can pass them as an object.

The method signature is: 

addImage(URL, width, height, caption)

addImage(imageDataObject)

{# Pass the individual image data values #}
{% do _page.jsonld.organization.addImage('/url/to/image.jpg', 300, 400, 'Image caption') %}

{# You can also only pass the URL #}
{% do _page.jsonld.organization.addImage('/url/to/image.jpg',) %}

{# Or, leave out the caption #}
{% do _page.jsonld.organization.addImage('/url/to/image.jpg', 300, 400) %}

{# Pass an object of information #}
{% do _page.jsonld.organization.addImage({
    url: '/url/to/image.jpg',
    width: 300,
    height: 400,
    caption: 'Image caption'
}) %}

addPhoto

Add one or more images and sets them under the photo data key. See https://schema.org/photo for more information.

addImage is the more common method to use instead of addPhoto.

This allows you to set multiple images when you call it multiple times.

You can either pass the image data as parameters or you can pass them as an object.

The method signature is: 

addPhoto(URL, width, height, caption)

addPhoto(imageDataObject)

{# Pass the individual image data values #}
{% do _page.jsonld.organization.addPhoto('/url/to/image.jpg', 300, 400, 'Image caption') %}

{# You can also only pass the URL #}
{% do _page.jsonld.organization.addPhoto('/url/to/image.jpg',) %}

{# Or, leave out the caption #}
{% do _page.jsonld.organization.addPhoto('/url/to/image.jpg', 300, 400) %}

{# Pass an object of information #}
{% do _page.jsonld.organization.addPhoto({
    url: '/url/to/image.jpg',
    width: 300,
    height: 400,
    caption: 'Image caption'
}) %}

setAddress

Set the address information. See https://schema.org/PostalAddress for more information.

You can either pass the address data as parameters, as an array of information, or as an Item object.

The method signature is: 

setAddress(streetAddress, addressLocality, addressRegion, postalCode, addressCountry)

setAddress(addressDataObject)

setAddress(addressItemObject)

{# Pass the individual image data values #}
{% do _page.jsonld.organization.setAddress('3 Main St', 'Orlando', 'FL', '12345', 'US') %}

{# Pass an object of information #}
{% do _page.jsonld.organization.setAddress({
    streetAddress: '3 Main St',
    addressLocality: 'Orlando',
    addressRegion: 'FL',
    postalCode: '12345',
    addressCountry: 'US'
}) %}

{# Create an Item object #}
{% set addr = _page.jsonld.create('address') %}
{% set addr.streetAddress = '123 Main St' %}
{% set addr.addressLocality = 'Springfield' %}
{% set addr.addressRegion = 'IL' %}
{% do addr.setPostalCode('62701') %}
{% do _page.jsonld.organization.setAddress(addr) %}

setDescription

Set the publisher description.

{% do _page.jsonld.organization.setDescription('description here') %}

setId

Set the id for the publisher.

This is done automatically by the Aptuitiv platform when a page is rendered.

{% do _page.jsonld.organization.setId('https://www.mysite.com/#organization-type') %}

setImage

Set a single image and sets it under the image data key. See https://schema.org/image for more information.

You can either pass the image data as parameters or you can pass them as an object.

The method signature is: 

setImage(URL, width, height, caption)

setImage(imageDataObject)

{# Pass the individual image data values #}
{% do _page.jsonld.organization.setImage('/url/to/image.jpg', 300, 400, 'Image caption') %}

{# You can also only pass the URL #}
{% do _page.jsonld.organization.setImage('/url/to/image.jpg',) %}

{# Or, leave out the caption #}
{% do _page.jsonld.organization.setImage('/url/to/image.jpg', 300, 400) %}

{# Pass an object of information #}
{% do _page.jsonld.organization.setImage({
    url: '/url/to/image.jpg',
    width: 300,
    height: 400,
    caption: 'Image caption'
}) %}

Set a single image and sets it under the logo data key. This is useful for setting the organization logo. See https://schema.org/logo for more information.

You can either pass the image data as parameters or you can pass them as an object.

The method signature is: 

setLogo(URL, width, height, caption)

setLogo(imageDataObject)

{# Pass the individual image data values #}
{% do _page.jsonld.organization.setLogo('/url/to/image.jpg', 300, 400, 'Image caption') %}

{# You can also only pass the URL #}
{% do _page.jsonld.organization.setLogo('/url/to/image.jpg',) %}

{# Or, leave out the caption #}
{% do _page.jsonld.organization.setLogo('/url/to/image.jpg', 300, 400) %}

{# Pass an object of information #}
{% do _page.jsonld.organization.setLogo({
    url: '/url/to/image.jpg',
    width: 300,
    height: 400,
    caption: 'Image caption'
}) %}

setName

Set the publisher name.

This is done automatically by the Aptuitiv platform when a page is rendered if the company name is set in the Company Information settings.

{% do _page.jsonld.organization.setName('Company name here') %}

setPhoto

Add a single image and sets it under the photo data key. See https://schema.org/photo for more information.

setImage is the more common method to use instead of setPhoto.

You can either pass the image data as parameters or you can pass them as an object.

The method signature is: 

setPhoto(URL, width, height, caption)

setPhoto(imageDataObject)

{# Pass the individual image data values #}
{% do _page.jsonld.organization.setPhoto('/url/to/image.jpg', 300, 400, 'Image caption') %}

{# You can also only pass the URL #}
{% do _page.jsonld.organization.setPhoto('/url/to/image.jpg',) %}

{# Or, leave out the caption #}
{% do _page.jsonld.organization.setPhoto('/url/to/image.jpg', 300, 400) %}

{# Pass an object of information #}
{% do _page.jsonld.organization.setPhoto({
    url: '/url/to/image.jpg',
    width: 300,
    height: 400,
    caption: 'Image caption'
}) %}

setType

Set the organization type.

This is done automatically by the Aptuitiv platform when a page is rendered if the organization type is set in the Structured Data Settings.

{% do _page.jsonld.organization.setType('LocalBusiness') %}

setUrl

{% do _page.jsonld.organization.setUrl('https://www.mysite.com') %}
This documentation is only for Aptuitiv CMS. Learn more.
Get Started With Aptuitiv