所以我运行一个Laravel 5.4项目,我们有一个系统,每个页面都需要单独的META标签才能正确显示人们发推文网址等等。所以我的问题:
如何将以下代码注入我的头标记?
e.g。新文章可能如下所示:
<meta name="twitter:card" content="summary">
<meta name="twitter:site" content="@mysite">
<meta name="twitter:title" content="News Article - Donald Trumps Twitter Deleted!">
<meta name="twitter:image" content="imageurl">
<meta name="twitter:description" content="Donald Trump lost access to his twitter for...">
<meta name="twitter:domain" content="https://www.example.com">
<meta name="description" content="Donald Trump lost access to his twitter for..."/>
<meta name="keywords" content="News, Donald, Trump, Media, Reporting, Urgent, Breaking, Twitter"/>
而论坛帖子的内容可能如下所示:
<meta name="twitter:card" content="summary">
<meta name="twitter:site" content="@mysite">
<meta name="twitter:title" content="Forum - Welcome to the forum!">
<meta name="twitter:image" content="imageurl">
<meta name="twitter:description" content="Hey there and welcome to our forum! For the chance to win $250 please...">
<meta name="twitter:domain" content="https://www.example.com">
<meta name="description" content="Hey there and welcome to our forum! For the chance to win $250 please..."/>
<meta name="keywords" content="Forum, Thread, Post, Win, Welcome, Twitter"/>
那么,怎么样?我花了一个小时来讨论这个问题让我很困惑!
答案 0 :(得分:0)
查看有关模板继承(https://laravel.com/docs/5.2/blade#template-inheritance)
的laravel文档您可以使用刀片中的<head></head>
将元数据注入@section('title',$article->title)
您的情况示例:
<head>
<meta name="twitter:title" content="@yield('twitter_title')">
<meta name="twitter:image" content="@yield('twitter_image')">
</head>
在你的刀片中:
@extends('layouts.layout') //This loads the default blade with your <head></head> section
@section('twitter_title',$article->title)
@section('twitter_image',$article->image)