lerni/silverstripe3-ldjsonrequirement

此包已被废弃,不再维护。未建议替代包。

为 SilverStripe 模板添加 type 为 application/ld+json 的 script 标签的补丁

安装: 170

依赖: 0

建议者: 0

安全: 0

星标: 0

关注者: 2

分支: 0

类型:silverstripe-patch

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

This package is auto-updated.

Last update: 2021-10-29 03:04:31 UTC


README

此补丁允许在 SS 3.x 中添加 type 为 application/ld+json 的 script 标签,用于结构化数据 schema.org。配合自定义的 Requirements_Backend,可以轻松添加任何模式。生成这些 json 块的舒适方式是 spatie/schema-org

工作原理

它添加了一个补丁,因为 Requirements 是一个标准的 php 类(不是 SS_Object)https://gist.github.com/lerni/582f500d3d9223ada4b7e9c155189b77

注册自定义的 Requirements_Backend,例如:https://gist.github.com/lerni/42a656c8a337754c33de0179762d1898

Requirements:
  backend: Requirements_BackendEnhancement

映射您希望在模型中公开的内容,例如

    use Spatie\SchemaOrg\Schema;

    public function LocalBusiness() {
        $schema = Schema::localBusiness()
            ->name($this->Title)
            ->email($this->EMail)
            ->contactPoint(
                Schema::contactPoint()
                    ->areaServed('Worldwide'));

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

        return $schema->toScript();
    }

并将其包含在模板中

    <% require ldJsonScript($LocalBusiness) %>

需求

  • SilverStripe ~3.7(仅测试了该版本)

安装

使用 composer: composer require lerni/silverstripe3-ldjsonrequirement