I have a markup pattern that will be used through the site, taking data from an ACF clone field with prefixed names. Here’s an example with a set of ACF data that is included in a CPT archive that extends the main App lasyout:
@extends('layouts.app')
@section('content')
<div class="title-group">
@if ($producer_intro_subtitle)
<h4>{!! $producer_intro_subtitle !!}</h4>
@endif
@if ($producer_intro_subtitle)
<h1>{!! $producer_intro_title !!}</h1>
@endif
@if ($producer_intro_text)
<p>{!! $producer_intro_text !!}</p>
@endif
@if ($producer_intro_text)
<a href="{!! $producer_fine_wine_list_download['url']!!}">{!! $producer_fine_wine_list_download['name']!!}</a>
@endif
</div>
@php ArchiveProducer::producerRegions() @endphp
@if (!have_posts())
<div class="alert alert-warning">
{{ __('Sorry, no results were found.', 'sage') }}
</div>
{!! get_search_form(false) !!}
@endif
@while (have_posts()) @php the_post() @endphp
@include('partials.content-'.get_post_type())
@endwhile
{!! get_the_posts_navigation() !!}
@endsection
I’d like to use this pattern again on other templates, accpeting different data. I could repeat the same markup and swap out the variables, but that isn’t the best approach.
I am thinking I should create a new layout in views/layouts:, like this:
<section class="title-group">
<h4>@yield('title-group__subtitle')</h4>
<h1>@yield('title-group__title')</h1>
<p>@yield('title-group__content')</p>
<a href="@yield('title-group__link')">@yield('title-group__link-name')</a>
</section>
Then extend that into my CPT archive (or elsewhere) and replace the yields with the data. However this is where I’m coming unstuck.
I’m imagining something like this:
@extends('title-group',['title-group__title' => '{!! $producer_intro_title !!}'])
But cannot figure it out. Any suggestions? Or is this just the wrong way to think about it?