mardi 3 octobre 2017

Laravel Blade: Show meta-tag only when variable is given on extend

This is the beginning of my master.blade.php

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>@yield('title')</title>
    <meta name="description" content="@yield('meta_desc')">

If I extend this to a page where no meta_desc is given like this:

@extends('layouts.index')

@section('title')
A nice title
@endsection

The this page has in the header a meta-tag with an empty description

<meta name="description" content="">

However I would like to skip the meta-tag completely, when no meta_desc is given. I tried to change the code in the master.blade.php to

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>@yield('title', )</title>
    @if(!empty($meta_desc))
    <meta name="description" content="@yield('meta_desc')">
    @endif 

but then the meta-tag

<meta name="description" content="">

would be always be missing then. How can I fix it?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire