So have this namespace in my config/views.php
/*
|--------------------------------------------------------------------------
| View Namespaces
|--------------------------------------------------------------------------
|
| Blade has an underutilized feature that allows developers to add
| supplemental view paths that may contain conflictingly named views.
| These paths are prefixed with a namespace to get around the conflicts.
| A use case might be including views from within a plugin folder.
|
*/
'namespaces' => [
'SVG' => get_theme_file_path() . '/resources/assets/svg',
],
Which allows me to grab SVGs within my blade templates much like normal partials like so:
<div class="icon">
@include('SVG::icons.phone')
</div>
I am wanting to be able to call one of those icons within a wp_menu a acf field I have that matches whats in that icons folder:
add_filter('wp_nav_menu_objects', function ($items, $args) {
foreach ($items as &$item) {
if (get_field('use_icon', $item)) {
if($icon = get_field('svg_icon', $item)) {
// THIS LINE DOESNT WORK
$item->title = App\template('SVG::icons.' . $icon);
}
}
}
return $items;
}, 10, 2);
I get this error:
Fatal error: Uncaught Symfony\Component\Debug\Exception\FatalThrowableError: Call to undefined function App\App\template() in /Users/mike/sites/glu-recruit/web/app/themes/glu-theme/app/filters.php:129 Stack trace:
#0 /Users/mike/sites/glu-recruit/web/wp/wp-includes/class-wp-hook.php(303): App\{closure}(Array, Object(stdClass))
#1 /Users/mike/sites/glu-recruit/web/wp/wp-includes/plugin.php(189): WP_Hook->apply_filters(Array, Array)
#2 /Users/mike/sites/glu-recruit/web/wp/wp-includes/nav-menu-template.php(226): apply_filters('wp_nav_menu_obj...', Array, Object(stdClass))
#3 /Users/mike/sites/glu-recruit/web/app/uploads/cache/f4e3467db59f0e198d9e321de1c372a12ebd6032.php(20): wp_nav_menu(Object(stdClass))
#4 /Users/mike/sites/glu-recruit/web/app/themes/glu-theme/vendor/illuminate/view/Engines/PhpEngine.php(43): include('/Users/mike/sit...')
#5 /Users/mike/sites/glu-recruit/web/app/themes/glu-theme/vendor/illuminate/view/Engines/CompilerEngine.php(59): Illuminate\View\Engines\PhpEngine->evaluatePath('/Users/mike/sit...', Array in /Users/mike/sites/glu-recruit/web/app/themes/glu-theme/app/filters.php on line 129
I am a bit lost as to how to get it to work. I know that you can use normal partials within hooks with the following:
<?php
echo App\template('partials.some-partial');
This is what lead me to my current solution that doesn’t work obviously so any help would be gratefully received