Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在laravel应用程序中创建动态元标记_Php_Laravel_Dynamic_Tags_Blade - Fatal编程技术网

Php 在laravel应用程序中创建动态元标记

Php 在laravel应用程序中创建动态元标记,php,laravel,dynamic,tags,blade,Php,Laravel,Dynamic,Tags,Blade,我正在尝试在我的laravel应用程序中实现动态元标记。我有一个head.blade.php文件,其中包含head中的所有代码。这就是我一直在做的,我在pages文件夹下创建了一个名为meta-conf.php的文件,head.blade.php包含- @if(Route::currentRouteName() != false) {{ $page = Route::currentRouteName(); }} @include('pages.meta-conf'); {{

我正在尝试在我的laravel应用程序中实现动态元标记。我有一个head.blade.php文件,其中包含head中的所有代码。这就是我一直在做的,我在pages文件夹下创建了一个名为meta-conf.php的文件,head.blade.php包含-

@if(Route::currentRouteName() != false) 
{{
    $page = Route::currentRouteName();
}}
    @include('pages.meta-conf');
{{
    $title = $meta[$page]['title'];
    $keywords = $meta[$page]['keywords'];
    $description = $meta[$page]['description'];
}}
@else
{{
   $title = "akademe";
   $keywords = "";
   $description = "Quickly find near by courses";
}}
@endif
<?php

$meta['index']['title'] = "Home";
$meta['index']['keywords'] = "explore, learn, repeat, education, register, institute, courses";
$meta['index']['description'] = "Quickly find near by courses";
meta-conf.php包含-

@if(Route::currentRouteName() != false) 
{{
    $page = Route::currentRouteName();
}}
    @include('pages.meta-conf');
{{
    $title = $meta[$page]['title'];
    $keywords = $meta[$page]['keywords'];
    $description = $meta[$page]['description'];
}}
@else
{{
   $title = "akademe";
   $keywords = "";
   $description = "Quickly find near by courses";
}}
@endif
<?php

$meta['index']['title'] = "Home";
$meta['index']['keywords'] = "explore, learn, repeat, education, register, institute, courses";
$meta['index']['description'] = "Quickly find near by courses";

我要做的而不是你在做的是:

  • 将标题、关键字和描述作为公共变量添加到基本控制器(
    app/Http/Controllers/Controller.php
  • 初始化控制器构造函数上的变量并设置“默认”值
  • 从控制器(课程、搜索等)设置每个页面的特定值
  • 在基本控制器上实现“renderPage”方法,以便可以从控制器传递视图和参数
  • Render方法将加载请求的视图并传递参数和元标记变量
  • 更新您的
    head.blade.php
    以使用元变量
我还没有测试过上述任何一项,但我认为这样做应该有效:)