A patch for SilverStripe to add script tags with type application/ld+json in template

dev-master 2019-05-29 06:44 UTC

This package is auto-updated.

Last update: 2020-06-29 08:56:33 UTC


This patch allows to add script tags with type application/ld+json to SS 3.x as used for structured data schema.org. In tandem with a custom Requirements_Backend you than can add any schema easily. A comfortable way to generate those json blobs is spatie/schema-org.

How it works

It adds a patch since Requirements is a standard php class (no SS_Object) https://gist.github.com/lerni/582f500d3d9223ada4b7e9c155189b77

Register a custom Requirements_Backend like: https://gist.github.com/lerni/42a656c8a337754c33de0179762d1898

  backend: Requirements_BackendEnhancement

Map what you like to expose in your Model like:

    use Spatie\SchemaOrg\Schema;

    public function LocalBusiness() {
        $schema = Schema::localBusiness()

        $schema->setProperty('@id', $this->Anchor());

        return $schema->toScript();

And include it in Template

    <% require ldJsonScript($LocalBusiness) %>


  • SilverStripe ~3.7 (just tested with that)


Use composer: composer require lerni/silverstripe3-ldjsonrequirement