将元标记添加到 laravel 页面

新手上路,请多包涵

我正在尝试向我的 Laravel 页面添加描述和关键字。

这种方式行得通吗?或者有什么问题?

 @section('title')
{{trans('strings.About')}}
@stop
@section('description', 'Share text and photos with your friends and have fun')
@section('keywords', 'sharing, sharing text, text, sharing photo, photo,')
@section('robots', 'index, follow')
@section('revisit-after', 'content="3 days')

原文由 Oleg Grytsenko 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 491
2 个回答

您是否正在扩展另一个使用所有这些 sections 的模板?他们不会自己工作,他们需要在另一个模板中填充占位符。

它应该是这样的:

 <!-- layouts.master -->
<html>
    <head>
        <title>App Name - @yield('title')</title>
        <meta name="description" content="@yield('description')">
        <meta name="keywords" content="@yield('keywords')">
        <!-- etc -->
    </head>
    <body>
        ...
    </body>
</html>

然后你的模板应该扩展另一个模板。

 @extends('layouts.master')
@section('title')
{{trans('strings.About')}}
@stop
@section('description', 'Share text and photos with your friends and have fun')
@section('keywords', 'sharing, sharing text, text, sharing photo, photo,')
@section('robots', 'index, follow')
@section('revisit-after', 'content="3 days')

至少,这就是我阅读他们文档的方式: https ://laravel.com/docs/5.2/blade

原文由 Adam Taylor 发布,翻译遵循 CC BY-SA 3.0 许可协议

您只能使用我在下面提到的所有这些重要标签创建一个部分。以及 @yield 应用程序布局中的这一部分 <head> HTML 代码部分。

 @section('meta_tags')
    @if($obj)
        <title>{{$obj->title}} - {{env('SITE_URL', 'Site Name')}}</title>
        <meta name='description' itemprop='description' content='{{$obj->description}}' />
        <?php $tags = implode(',', $obj->tags); ?>
        <meta name='keywords' content='{{$tags}}' />
        <meta property='article:published_time' content='{{$obj->created_at}}' />
        <meta property='article:section' content='event' />

        <meta property="og:description" content="{{$obj->description}}" />
        <meta property="og:title" content="{{$obj->title}}" />
        <meta property="og:url" content="{{url()->current()}}" />
        <meta property="og:type" content="article" />
        <meta property="og:locale" content="en-us" />
        <meta property="og:locale:alternate" content="en-us" />
        <meta property="og:site_name" content="{{env('SITE_URL', 'Site Name')}}" />
        @foreach($obj->images as $image)
            <meta property="og:image" content="{{$image->url}}" />
        @endforeach
        <meta property="og:image:url" content="{{obj->image}}" />
        <meta property="og:image:size" content="300" />

        <meta name="twitter:card" content="summary" />
        <meta name="twitter:title" content="{{$obj->title}}" />
        <meta name="twitter:site" content="@BrnBhaskar" />
    @endif
@endsection

原文由 Brn.Rajoriya 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题