I have an anonymous component layout.blade.php
that has the following props and how they are used, some meta tags have been removed for brevity:
@props([
'meta' => [
'title' => 'Some title',
'description' => 'Some description',
'url' => 'https://somesite.com',
'image' => 'images/banner.png',
],
'robots' => 'index, follow',
'keywords' => 'some, comma, separated, keywords'
])
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="description" content="{{ $meta['description'] }}">
<meta name="robots" content="{{ $robots }}" />
<meta name="keywords" content="{{ $keywords }}" />
<meta property="og:type" content="website" />
<meta property="og:title" content="{{ $meta['title'] }}"/>
<meta property="og:description" content="{{ $meta['description'] }}" />
<meta property="og:url" content="{{ $meta['url'] }}" />
<meta property="og:image" content="{{asset($meta['image'])}}" />
<meta property="twitter:title" content="{{ $meta['title'] }}" />
<meta property="twitter:description" content="{{ $meta['description'] }}" />
<link rel="canonical" href="{{ $meta['url'] }}"/>
<title>{{ $meta['title'] }}</title>
</head>
Whenever I pass data via a controller e.g.:
return(view('plans.index', [
'plans' => auth()->user()->plans()->get(),
'robots' => 'noindex'
]));
The meta
prop will always resolve to the correct values passed, whether that is default or something I provide.
In the case of robots
and keywords
they always are the defaults provided. I can't find any documentation that explains this behaviour and can't see where I am going wrong.
EDIT: An example of how the layout is being called is below:
<x-layout>
@section('content')
<section >
@include('partials.hero')
</section>
<section id="features" >
@include('partials.explainer')
</section>
<section id="waitlist" >
@include('partials.form')
</section>
@endsection
</x-layout>
CodePudding user response:
As the documentation says, You should PASS the variables you want to the anonymous component, so you should call your layout component as so:
<x-layout :robots="$robots" :keywords="$keywords">