Including partial from partial in Sage 9/Blade

Hi all…!

I’ve got a bit of a strange issue with Sage 9/Blade, and I was hoping someone might be able to shed some light on it.

In partials/footer.blade.php I’m trying to include another partial (contact-details.blade.php) in the same directory, but am getting a fatal error.

I’ve noticed in, for example, content-single.blade.php the format for including another partial is

@include('partials/path-to-partial) rather than the dot syntax, and I’ve tried both in my case

Error:

 ErrorException: Call to a member function make() on null (View: /Users/dougbelchamber/Workplace/site/wp-content/themes/theme/templates/layouts/base.blade.php) (View: /Users/dougbelchamber/Workplace/site/wp-content/themes/theme/templates/layouts/base.blade.php) in /Users/dougbelchamber/Workplace/site/wp-content/uploads/cache/compiled/bfd3a125bf73746ddbf7c7ba0c4773a0905c7a71.php on line 5
Call Stack

(Discourse looks like it’s going to truncate some of the error, so here’s a PasteBin: http://pastebin.com/uErV8QJU)

File structure: https://www.evernote.com/l/AOMLK8Zto19Ig5oeYuzFgLZheID7D2pWFn4B/image.png

Even when the 2nd partial is completely empty, I’m seeing this error.

What am I missing? :slight_smile:

Thanks.

Hi - just an update…!

While rushing out, one slightly crucial thing I might have neglected to mention (my bad!) is that I am going slightly off-piste with the footer…

In base.blade.php, I have removed the reference to @include('partials.footer') and elsewhere in my theme, as I did in Sage 8, I hook into wp_footer and conditionally show the contents of the footer template part depending on the value of a custom field.

add_action( 'wp_footer', function() {
    Utils::is_site_footer_disabled() ?: include \App\template_path( locate_template( 'templates/partials/footer.blade.php' ) );
}, 10 );

I’ve modified this for Sage 9; previously it was just a get_template_part() call to the footer template part.

So to recap:

  • Base.php (in my case) doesn’t have @include('partials.footer')
  • I conditionally call the footer using include \App\template_path( locate_template( 'templates/partials/footer.blade.php' ) ) by hooking into `wp_footer
  • Calling the footer template part in this way works until I then also call a template part using blade (ie @include) within footer.blade.php
  • To be able to call a partial from a partial that’s not been called by blade, I can use @php (include \App\template_path( locate_template( 'templates/partials/contact-details.blade.php' ) ) )

Perhaps there’s a way to include the template part when I hook into wp_footer which will allow for @include() to be used… I’ll continue to play with some of the helper functions and report back!

OK, so this is what I have, and I think is a good solution:

add_action( 'wp_footer', function() {
    echo Utils::is_site_footer_disabled() ?: \App\template( 'partials.footer' );
}, 10 );

and then I can use @include('partials.contact-details') within the template part.

2 Likes

Dude. Thank you very very very much.