Skip to main content

✂️ Schema snippets

Below you'll find a collection of useful schema snippets. Use these as a starting point or inspiration when designing your next schema.

info

These snippets are meant as examples and are meant to be modified to fit your own data structure.

Map all source entity properties

A schema which dynamically maps all properties from your source entity to the view.

/** @type {Enterspeed.FullSchema} */
export default {
triggers: function(context) {
context.triggers('cms', ['contentPage']);
},
routes: function(sourceEntity, context) {
context.url(sourceEntity.url);
},
properties: function (sourceEntity, context) {
return sourceEntity.properties;
}
}

Site settings

A schema containing essential site settings, here Site name, Logo and Login page link.

Site settings
/** @type {Enterspeed.FullSchema} */
export default {
triggers: function(context) {
context.triggers('cms', ['site']);
},
routes: function(sourceEntity, context) {
context.handle('settings');
},
properties: function (sourceEntity, context) {
const p = sourceEntity.properties;
return {
siteName: p.siteName,
logo: p.logo[0].url,
loginPage: context
.reference("linkItem")
.byOriginId(p.loginPage[0].id),
};
}
}

SEO Composition

A schema for basic SEO settings, here meta title, meta description and meta robots (index/noindex and follow/nofollow).

This schema can be used in other schemas using the reference type as you can see in the code below.

SEO Composition
/** @type {Enterspeed.FullSchema} */
export default {
triggers: function(context) {
context.triggers("cms", ["frontpage", "article", "articles"]);
},
properties: function (sourceEntity, context) {
const p = sourceEntity.properties;
return {
title: p.seoTitle,
description: p.seoDescription,
robots: {
follow: p.robotsFollow,
index: p.robotsIndex,
},
};
}
}

How the SEO Composition schema will be used in another schema afterwards:

SEO Composition used in another schema
/** @type {Enterspeed.FullSchema} */
export default {
triggers: function(context) {
context.triggers("cms", ["article"]);
},
properties: function (sourceEntity, context) {
return {
seoComposition: context
.reference("seoComposition")
.byOriginId(sourceEntity.originId),
};
}
}

A schema for generating a breadcrumb navigation.

This schema can be used in other schemas using the reference type, as you can see in the code below.

SEO Composition used in another schema
/** @type {Enterspeed.FullSchema} */
export default {
triggers: function(context) {
context.triggers("cms", ["homePage", "contentPage"]);
},
properties: function (sourceEntity, context) {
return {
link: {
name: sourceEntity.properties.metaData.name,
url: sourceEntity.url,
originId: sourceEntity.originId,
},
level: sourceEntity.properties.metaData.level,
};
}
}

How the Breadcrumb item schema will be used in another schema afterwards:

SEO Composition used in another schema
/** @type {Enterspeed.FullSchema} */
export default {
triggers: function(context) {
context.triggers("cms", ["contentPage"]);
},
properties: function (sourceEntity, context) {
return {
breadcrumbs: context
.reference("seoComposition")
.byOriginIds(sourceEntity.properties.metaData.nodePath),
};
}
}

Category products

A schema for listing all the products related to a specific category.

/** @type {Enterspeed.FullSchema} */
export default {
triggers: function(context) {
context.triggers("cms", ["category"]);
},
routes: function(sourceEntity, context) {
context.url("/categories/" + sourceEntity.properties.slug);
},
properties: function (sourceEntity, context) {
return {
title: sourceEntity.properties.name,
description: sourceEntity.properties.description,
products: context
.reference("product")
.filter(`type eq 'product' and properties.categoryId eq '${sourceEntity.originId}'`)
};
}
}

Top 3 product reviews

A schema for listing the 3 highest-rated product reviews.

/** @type {Enterspeed.FullSchema} */
export default {
triggers: function(context) {
context.triggers("cms", ["reviews"]);
},
properties: function (sourceEntity, context) {
return {
title: sourceEntity.properties.name,
description: sourceEntity.properties.description,
reviews: context
.reference("review")
.filter("type eq 'review' and properties.hashtags/any(t: t eq '#productreviews')")
.orderBy({propertyName: "properties.rating", direction: "asc"})
.limit(3)
};
}
}