I have this in my Page controller:
public static function pageHeaderImage()
{
if ( (get_field( 'page_header_style') == "Quote" || get_field( 'page_header_style') == "Basic") && get_field( 'show_featured_image') == "Yes") {
the_post_thumbnail('w890h500');
}
return;
}
Which is accessed in a partial:
<div class="d-flex align-items-center">
@php Page::pageHeaderImage() @endphp
@include('partials.page-header-text', [
'subtitle' => $page_header_subtitle,
'title' => $page_header_title,
'text' => $page_header_text,
])
</div>
I’d like to pass through an additional value in that function, like this:
public static function pageHeaderImage()
{
if ( (get_field( 'page_header_style') == "Quote" || get_field( 'page_header_style') == "Basic") && get_field( 'show_featured_image') == "Yes") {
the_post_thumbnail('w890h500');
**$class = 'has-img';**
}
return;
}
Then access that variable in my partial, like:
<div class="d-flex align-items-center **{{ $class }}**">
@php Page::pageHeaderImage() @endphp
@include('partials.page-header-text', [
'subtitle' => $page_header_subtitle,
'title' => $page_header_title,
'text' => $page_header_text,
])
</div>
I have experimented with returning an array from the fuction like:
public static function pageHeaderImage($header_img)
{
if ( (get_field( 'page_header_style') == "Quote" || get_field( 'page_header_style') == "Basic") && get_field( 'show_featured_image') == "Yes") {
$image = get_post_thumbnail('w890h500');
$class = 'has-img';
}
return array($image, $class);
}
Then attempting to access in the partial like:
<div class="d-flex align-items-center **@php list($class) = Page::pageHeaderImage($header_img) @endphp**">
**@php list($image) = Page::pageHeaderImage($header_img) @endphp**
@include('partials.page-header-text', [
'subtitle' => $page_header_subtitle,
'title' => $page_header_title,
'text' => $page_header_text,
])
</div>
If I dump the function call:
@dump(list($image) = Page::pageHeaderImage($header_img))
If it returns true I get:
array(2) { [0]=> string(0) "" [1]=> string(7) "has-img" }
If it returns false I get:
array(2) { [0]=> NULL [1]=> NULL }
The issue i’m having is how to output those variables, and how to do it in the cleanest Sage way.
Thanks