2

我想实现 facebook 分享按钮功能,它会在用户点击分享按钮期间捕获元标记信息。

我有一个 head.blade.php,其中包含一些要捕获的元标记。例子

<meta property="og:url" content="@yield('facebook_share_url')">
<meta property="og:image" content="@yield('facebook_share_image')">
<meta property="og:description" content="@yield('facebook_share_description')">

我有一个default.blade.php。

<!doctype html>
<html>
<head>
    @include('includes.head')
</head>
<body>
<div class="container">

    <header class="row">
        @include('includes.header')
    </header>

    <div id="main" class="row">
        @yield('content')
    </div>
</div>

@include('includes.footer')
</body>
</html>

因此,当我浏览到某个 url 说 www.example.com/details 时,default.blade.php 将产生来自这个 details.blade 的内容。此时我想更改 facebook 元标记属性,所以我在详细信息页面中做了如下操作。

@section('facebook_share_image', 'This is a description')
@section('facebook_share_description', 'This is an individual page title')

代码工作正常,但我想从我的视图数据中呈现它。就像是@section('facebook_share_description', {{ $data->description }})

但是当我检查我的元标记时,它什么也没给我。有可能这样做吗?

4

1 回答 1

6

我不确定这是您想要的还是您正在寻找的,但为什么不尝试仅将meta标签放在default.blade.php中而不是将其放在部分中。

例如,在headdefault.blade.php 的标签中插入:

@yield('facebook_meta')

view_file.blade.php

@section('facebook_meta')
    <meta property="og:url" content="Place your data here">
    <meta property="og:image" content="Place your data here">
    <meta property="og:description" content="Place your data here">
@endsection

据我说,上述方法效果更好。

也许这可以帮助你。

于 2015-12-19T07:13:58.883 回答