Controllers returning unknown variable?

My App.php controller:

namespace App\Controllers;

use Sober\Controller\Controller;

class App extends Controller
{   
    protected $acf = true;

    public function siteName()
    {
        return get_bloginfo('name');
    }
}

When I try to output in a template using {!! $site_name !!} or {!! $acf_field_name !!} I get a php unknown variable error.

ErrorException thrown with message “Undefined variable: site_name (View: C:\Users\paperrobots\Documents\Projects\SCORG\web\app\themes\SCORG_2020\resources\views\partials\header.blade.php) (View: C:\Users\paperrobots\Documents\Projects\SCORG\web\app\themes\SCORG_2020\resources\views\partials\header.blade.php) (View: C:\Users\paperrobots\Documents\Projects\SCORG\web\app\themes\SCORG_2020\resources\views\partials\header.blade.php)”

Stacktrace:
#29 ErrorException in C:\Users\paperrobots\Documents\Projects\SCORG\web\app\uploads\cache\bfd15010dbbe4f3026104b2eb0106bee1cc68c3d.php:6
#28 ErrorException in C:\Users\paperrobots\Documents\Projects\SCORG\web\app\uploads\cache\bfd15010dbbe4f3026104b2eb0106bee1cc68c3d.php:6
#27 ErrorException in C:\Users\paperrobots\Documents\Projects\SCORG\web\app\uploads\cache\bfd15010dbbe4f3026104b2eb0106bee1cc68c3d.php:6
#26 Whoops\Exception\ErrorException in C:\Users\paperrobots\Documents\Projects\SCORG\web\app\uploads\cache\bfd15010dbbe4f3026104b2eb0106bee1cc68c3d.php:6
#25 Whoops\Run:handleError in C:\Users\paperrobots\Documents\Projects\SCORG\web\app\uploads\cache\bfd15010dbbe4f3026104b2eb0106bee1cc68c3d.php:6
#24 include in C:\Users\paperrobots\Documents\Projects\SCORG\web\app\themes\SCORG_2020\vendor\illuminate\view\Engines\PhpEngine.php:43
#23 Illuminate\View\Engines\PhpEngine:evaluatePath in C:\Users\paperrobots\Documents\Projects\SCORG\web\app\themes\SCORG_2020\vendor\illuminate\view\Engines\CompilerEngine.php:59
#22 Illuminate\View\Engines\CompilerEngine:get in C:\Users\paperrobots\Documents\Projects\SCORG\web\app\themes\SCORG_2020\vendor\illuminate\view\View.php:142
#21 Illuminate\View\View:getContents in C:\Users\paperrobots\Documents\Projects\SCORG\web\app\themes\SCORG_2020\vendor\illuminate\view\View.php:125
#20 Illuminate\View\View:renderContents in C:\Users\paperrobots\Documents\Projects\SCORG\web\app\themes\SCORG_2020\vendor\illuminate\view\View.php:90
#19 Illuminate\View\View:render in C:\Users\paperrobots\Documents\Projects\SCORG\web\app\uploads\cache\75223c4e07deec0bcf32f30113b7755af0ee0621.php:6
#18 include in C:\Users\paperrobots\Documents\Projects\SCORG\web\app\themes\SCORG_2020\vendor\illuminate\view\Engines\PhpEngine.php:43
#17 Illuminate\View\Engines\PhpEngine:evaluatePath in C:\Users\paperrobots\Documents\Projects\SCORG\web\app\themes\SCORG_2020\vendor\illuminate\view\Engines\CompilerEngine.php:59
#16 Illuminate\View\Engines\CompilerEngine:get in C:\Users\paperrobots\Documents\Projects\SCORG\web\app\themes\SCORG_2020\vendor\illuminate\view\View.php:142
#15 Illuminate\View\View:getContents in C:\Users\paperrobots\Documents\Projects\SCORG\web\app\themes\SCORG_2020\vendor\illuminate\view\View.php:125
#14 Illuminate\View\View:renderContents in C:\Users\paperrobots\Documents\Projects\SCORG\web\app\themes\SCORG_2020\vendor\illuminate\view\View.php:90
#13 Illuminate\View\View:render in C:\Users\paperrobots\Documents\Projects\SCORG\web\app\uploads\cache\b5f64a41299dc56cf5b8d745600086698f0d0682.php:102
#12 include in C:\Users\paperrobots\Documents\Projects\SCORG\web\app\themes\SCORG_2020\vendor\illuminate\view\Engines\PhpEngine.php:43
#11 Illuminate\View\Engines\PhpEngine:evaluatePath in C:\Users\paperrobots\Documents\Projects\SCORG\web\app\themes\SCORG_2020\vendor\illuminate\view\Engines\CompilerEngine.php:59
#10 Illuminate\View\Engines\CompilerEngine:get in C:\Users\paperrobots\Documents\Projects\SCORG\web\app\themes\SCORG_2020\vendor\illuminate\view\View.php:142
#9 Illuminate\View\View:getContents in C:\Users\paperrobots\Documents\Projects\SCORG\web\app\themes\SCORG_2020\vendor\illuminate\view\View.php:125
#8 Illuminate\View\View:renderContents in C:\Users\paperrobots\Documents\Projects\SCORG\web\app\themes\SCORG_2020\vendor\illuminate\view\View.php:90
#7 Illuminate\View\View:render in C:\Users\paperrobots\Documents\Projects\SCORG\web\app\themes\SCORG_2020\vendor\roots\sage-lib\Template\Blade.php:58
#6 Roots\Sage\Template\Blade:render in C:\Users\paperrobots\Documents\Projects\SCORG\web\app\themes\SCORG_2020\app\helpers.php:55
#5 App\template in C:\Users\paperrobots\Documents\Projects\SCORG\web\app\themes\SCORG_2020\app\filters.php:63
#4 App{closure} in C:\Users\paperrobots\Documents\Projects\SCORG\web\wp\wp-includes\class-wp-hook.php:287
#3 WP_Hook:apply_filters in C:\Users\paperrobots\Documents\Projects\SCORG\web\wp\wp-includes\plugin.php:206
#2 apply_filters in C:\Users\paperrobots\Documents\Projects\SCORG\web\wp\wp-includes\template-loader.php:104
#1 require_once in C:\Users\paperrobots\Documents\Projects\SCORG\web\wp\wp-blog-header.php:19
#0 require in C:\Users\paperrobots\Documents\Projects\SCORG\web\index.php:6

I’ve done this before on other sites without issue, did I miss something?

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