px_semantic 2.5.0 (beta)
, (*1)
Structured Data Markup Rendering for TYPO3 with JSON-LD, (*2)
PxSemantic provides an extrem dynamic and highly customizable solution to embed structured data on your website
and enrich them with information about your website. The currently supported classes are a subset of the vocabulary
defined on https://schema.org/ and were generated with the schema generator from https://api-platform.com/. At the
moment we only support json-ld format to encode LinkedData., (*3)
Before you start:
* Download / Import from TER or GitHub
* Install the Extension
* Include Static Template Files!, (*4)
For example you want to markup your official website with information about your corporate contacts
(https://developers.google.com/structured-data/customize/contact-points) you can do it this way:, (*5)
Declare your organization information and corporate contact via TypoScript., (*6)
TypoScript:
lib.structuredDataMarkupOrganization
Use the TS to render the resulting JSON-LD code somewhere on your website. We put it into the <HEAD>
because other
meta information are also located within the <HEAD>
tag. But it doesn`t matter., (*7)
Google says:, (*8)
You can embed data in a web page using schema.org field names and the new JSON-LD data format. JSON-LD is easy to
produce with many widely available JSON encoders. The data, enclosed within the
tags as shown in the examples below, may be placed in either the
, (*9)
or region of the page that displays that event. Either way, it won't affect how your document appears
in users' web browsers.
-- [Google Documentation][1]
TypoScript:
page.headerData.1453734422
If you want to put it in your template you could make use fluids cObject
-ViewHelper:, (*10)
Fluid:
<f:cObject typoscriptObjectPath="lib.structuredDataMarkupOrganization"></f:cObject>
This will result in the following JSON-LD Markup on your page, (*11)
<script type="application/ld+json">
{
"@context" : "http://schema.org",
"@type" : "Organization",
"areaServed":"DE"
"url" : "http://www.your-company-site.com",
"contactPoint" : {
"@type" : "ContactPoint",
"areaServed":"DE",
"telephone" : "+49-123-456-78",
"contactType" : "customer support"
},
"logo": {
"@type":"ImageObject",
"url":"http://www.your-company-site.com/fileadmin/company_logo.png"
},
"sameAs":[
"http:\\www.facebook.com\yourSite",
"http:\\www.youtube.com\user\yourSite",
"http:\\www.pinterest.com\yourSite\"
]
}
</script>
Example 2 - Render Multiple Entities
TypoScript:, (*12)
lib.structuredDataMarkupExample
Fluid:, (*13)
<f:for each="{entities}" as="entity">
{entity -> f:cObject(typoscriptObjectPath: 'lib.structuredDataMarkupExample')}
</f:for>
Example 3 - Create LinkedData REST API
Since version 2.0.0 it is possible to configure an LinkedData REST API which is based on Hydra Core Vocabulary (http://www.hydra-cg.com/spec/latest/core/), (*14)
TypoScript:, (*15)
- create a page e.g. called "api (123)" within your page tree for better realurl configuration
constants.txt, (*16)
plugin.tx_pxsemantic {
settings {
rest {
pid = 123
}
}
}
}
- now configure for each endpoint of your rest api the resource to entity mapping like in the easy example below
- as for strcutured data markup in exampe 1 and example 2 you could (re)use
processors
to transform your
resource (aka domain model) into an http://schema.org/ entity
setup.txt, (*17)
plugin.tx_pxsemantic {
settings {
rest {
endpoints {
pages {
entity = Portrino\PxSemantic\SchemaOrg\CreativeWork
resource = Portrino\PxSemantic\Domain\Model\Page
processors {
0 {
className = Portrino\PxSemantic\Processor\PageProcessor
}
}
}
}
}
}
}
}
- add this realurl configuration for nicer uris of your rest API
realurl_conf.php, (*18)
...
'fixedPostVars' => [
'_DEFAULT' => [],
'api' => [
[
'GETvar' => 'type',
'valueMap' => [
'structured-data' => 1475825939,
'structured-data-contexts' => 1476721757,
'vocab' => 1476770090
]
],
[
'GETvar' => 'tx_pxsemantic_hydraapi[endpoint]',
'valueMap' => [
'recipes' => 'recipes',
'pages' => 'pages'
],
'noMatch' => 'bypass'
],
[
'GETvar' => 'tx_pxsemantic_hydracontext[context]',
'valueMap' => [
'Entrypoint' => 'Entrypoint',
],
'noMatch' => 'bypass'
],
[
'cond' => [
'prevValueInList' => 'pages'
],
'GETvar' => 'tx_pxsemantic_hydraapi[uid]',
'lookUpTable' => [
'table' => 'pages',
'id_field' => 'uid',
'alias_field' => 'uid'
],
'optional' => true
]
],
'123' => 'api'
],
...
-
now you can call your Linked Data REST API via: http://domain.tld/api/structured-data/pages/ which will be presented
as PagedCollection (http://www.hydra-cg.com/spec/latest/core/#collections), (*19)
-
add this url to hydra console (http://www.markus-lanthaler.com/hydra/console/) will give you a nice hydra documentation, (*20)
More Examples
, (*22)
-
André Wuttig - Initial work, Semantic REST API, Documentation - aWuttig
-
Axel Böswetter - some more semantic.org entities - EvilBMP
See also the list of contributors who participated in this project., (*23)