ACF variables in blade template

I’m currently working like this:

Controller (controllers/Home.php)

public function location()
{
    return (object) array(
        'title' => get_field('location_title'),
        'button_text' => get_field('location_button_text'),
        'button_link' => get_field('location_button_link')['url'],
    );
}

View (simplified)

<h2>{{ $location->title }}</h2>
<a href="{{ $location->button_link }}">{{ $location->button_text }}</a>

I like object syntax personally.

I split my templates down into components (location is a component used on the home page) and then use a method per component. I feel like this keeps everything nice and logical.

14 Likes