Php Laravel如何在多个页面上包含Schema.org结构化数据
我正在构建一个Php Laravel如何在多个页面上包含Schema.org结构化数据,php,laravel,schema.org,Php,Laravel,Schema.org,我正在构建一个laravel-应用程序,其中我希望包含一些schema.org结构化数据。在我的app.blade.php-文件中,这是一个布局文件-我包括以下内容: <script type="application/ld+json"> { "@context": "http://schema.org", "@type": "WebSite", "name": "thecompany.com", "alternateName": "the compa
laravel
-应用程序,其中我希望包含一些schema.org
结构化数据。在我的app.blade.php
-文件中,这是一个布局文件-我包括以下内容:
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "WebSite",
"name": "thecompany.com",
"alternateName": "the company",
"url": "{{ route('home') }}"
}
</script>
{
“@context”:”http://schema.org",
“@type”:“网站”,
“名称”:“thecompany.com”,
“替代名称”:“公司”,
url:“{route('home')}}”
}
现在我想添加不同的参数,取决于我是哪个子页面。例如,我有一个作业列表页面,我希望每个作业页面都有如下内容:
{
"@context" : "https://schema.org/",
"@type" : "JobPosting",
"title" : "Software Engineer",
"description" : "<p>Become our next developer.</p>",
"employmentType" : "CONTRACTOR",
"hiringOrganization" : {
"@type" : "Organization",
"name" : "The Company",
"sameAs" : "http://www.google.com",
"logo" : "http://www.example.com/images/logo.png",
"baseSalary": {
"@type": "MonetaryAmount",
"currency": "USD",
"value": {
"@type": "QuantitativeValue",
"value": 40.00,
"unitText": "HOUR"
}
}
}
{
“@context”:”https://schema.org/",
“@type”:“职位发布”,
“职称”:“软件工程师”,
“说明”:“成为我们的下一个开发者。”,
“雇员类型”:“承包商”,
“雇佣组织”:{
“@type”:“组织”,
“名称”:“公司”,
“sameAs”:http://www.google.com",
“徽标”:http://www.example.com/images/logo.png",
“基本工资”:{
“@type”:“MonetaryAmount”,
“货币”:“美元”,
“价值”:{
“@type”:“QuantitativeValue”,
“价值”:40.00,
“单位文本”:“小时”
}
}
}
当然,这些值的变化取决于您在哪个作业页面上
我试图在job.blade.php
-文件中添加脚本,但它似乎被app.blade.php
-文件中的脚本覆盖
我怎样才能解决这个问题呢?你调查过了吗
您可以使用一些默认值构建架构组件,并将其包含在工作站点中:
schema.blade.php
<script type="application/ld+json">
"@context" : "https://schema.org/",
{{ $slot }}
</script>
@component('schema')
"@type" : "JobPosting",
"title" : "Software Engineer",
"description" : "<p>Become our next developer.</p>",
....
@endcomponent
另一种选择是使用类似 这允许您编写如下代码:
use Spatie\SchemaOrg\Schema;
$localBusiness = Schema::localBusiness()
->name('Spatie')
->email('info@spatie.be')
->contactPoint(Schema::contactPoint()->areaServed('Worldwide'));
echo $localBusiness->toScript();
…生成以下JSON-LD:
<script type="application/ld+json">
{
"@context": "http:\/\/schema.org",
"@type": "LocalBusiness",
"name": "Spatie",
"email": "info@spatie.be",
"contactPoint": {
"@type": "ContactPoint",
"areaServed": "Worldwide"
}
}
</script>
{
“@context”:“http:\/\/schema.org”,
“@type”:“LocalBusiness”,
“名称”:“空间”,
“电子邮件”:info@spatie.be",
“接触点”:{
“@type”:“联系人”,
“区域服务”:“全球”
}
}
您是否有一个在模板中呈现的解决方案?通常,我在一个模板中生成代码,然后简单地在关闭
标记上方的布局视图中打印出来,如下所示:{!!$schema!!}
。