Extend custom base.php to child pages

Hi, so I need a seperate menu bar/sidebar layout on one of the subpages of my site so I have created a base-page-custom.php which works. The problem I’m running into is that further child pages revert back to the default base.php. Is there a way to extend base-page-custom.php to child pages? E.g. a custom base.php for /sub-page also applies to /sub-page/child-page. I’m fairly new to Sage so it’s entirely possible I’m missing something simple/obvious. Thanks.

You could:

EDITED: Originally I wrote a long post here about how to do this with Blade @stacks, not realizing that the original poster was looking for help with Sage 8. I’ve modified this post to be a better example, and left it here in case it helps someone in the future.

A different approach to the whole problem might be a custom template, some basic logic, and a couple of blade @stacks.

Here’s an example of how @stacks work.

How to do this with Blade @stacks and Sage 9


 * Determine if the stack has content.
 * Credit to KimH for this function
 * @param  string $stack
 * @return boolean
function stack_has_content(string $stack) : bool
    return (boolean) trim(sage('blade')->yieldPushContent($stack));


<!doctype html>
<html @php(language_attributes())>
  <body @php(body_class())>

      @stack('header') <!-- add a header stack here -->



    <div class="wrap container" role="document">
      <div class="content">
        <main class="main">
        @if (App\display_sidebar())
          <aside class="sidebar">

              @stack('sidebar') <!-- add a header stack here -->





  Template Name: Custom Template

<!-- populate the header stack with this include -->

<!-- populate the sidebar stack with this include -->

<!-- continue about our normal custom template -->

  @while(have_posts()) @php(the_post())



<!-- all your custom header html here -->  




<!-- all your custom sidebar html here -->  


I cannot stress enough that this is untested, but it’s the general idea.

Stacks are super helpful for situations like this because they let you keep all your custom template stuff in one place (the custom template blade file), rather than messing around with a lot of logic, or a separate layout.

I hope this helps someone, some time.


I believe he was talking about sage8 :smile:
I’d just try to keep it simple and push those part of the layout further down the line to avoid having to create separate layouts.

… yup.

I’ll just… be over here.

1 Like

OK I’ve updated the above post to be a) a smarter approach and b) obviously called out as not the answer to OP’s question. Sorry to fill up so much space!

1 Like