Roots Discourse

How to parse an ACF Object called from the Controller to View?

Ok, so I have about 4 fields that are supposed to be global on the entire site. I thought of having a public function on the App.php controller that returns an object with those 4 ACF variables so they can be called from whatever view php file.

This is the App.php code

    public function globalAcf()

    return (object) array(
        'phone_Number' => get_field('phone_number', 'option'),
        'state' => get_field('state', 'option'),
        'city' => get_field('city', 'option'),
        'zipcode' => get_field('zipcode', 'option')


On the view, I am planning to just call these variables as

<h2> {{ $globalAcf -> zip }} </h2>

but of course, it doesn’t work. I am trying to figure out why and I am sure it’s because of some stupid obvious reason but as you can tell I am not that experienced.

You’re calling your variable with the incorrect name in your blade. Controller converts camelCase method names to snake_case variables, so you need $global_acf. This is explained in the Controller documentation.


I knew I missed something that was pretty obvious. Thanks for your help!

@dump will dump all variables so you can see what your target it. It’s a great way to troubleshoot.


This topic was automatically closed after 42 days. New replies are no longer allowed.