Child theme with sage 10

Is there any proper guide for setting up the child theme with sage 10? I am using sage 10 as my main theme on WordPress and for customizations, I have to create the child theme. I tried following this discussion to create the child theme and it does not work. Changing the parent theme’s namespace to Parent (from App) breaks the connection between composers and views, data does not go to the views.

Child theme is activated.

getting this error

Undefined variable $heroBackground in section-page-header.blade.php
$heroBackground is defined in the Parent\View\Composers\App.php

in the child App.php I have the following code

<?php

namespace App\View\Composers;

use Roots\Acorn\View\Composer;

class App extends Composer
{
}

And in the child theme’s App\Providers\ThemeServiceProvider

<?php

namespace App\Providers;

use Roots\Acorn\ServiceProvider;

class ThemeServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }

    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        //this outputs the correct data from the parent function
        dd((new \Parent\View\Composers\App())->getColorScheme());
    }
}

I have changed the namespaces in my composer.json files as well.
Parent composer file

"autoload": {
    "psr-4": {
      "Parent\\": "app/"
    }
  },

Child theme composer file

"autoload": {
    "psr-4": {
      "App\\": "app/",
      "Parent\\": "./../theme-name/app"
    }
  }

This is how my child theme’s structure looks like. Screenshot-2022-02-04-at-16-34-23 — ImgBB

Any hint about where to go from this point will be much appreciated.

1 Like

Hello! Have you found detailed guide on how to create child theme for Sage 10? I can’t find any discussing about this since February, 2022.
Can you please give me the URL that will help me with this question?

Also looking for a way to create a child theme but there seems to be no documentation about this. Would be nice if this would be more openly supported/discussed as it is a commonly used functionality of WordPress

Taken from the Sage development ebook:

Sage is not a theme framework, it is a starter theme. You should rarely need to update it, and typically you shouldn’t create child themes from it

What you can do is to share views between different themes using a plugin with namespaces.

/*
    // inside themes/sage10/config/view.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' => [
        /*
         | Given the below example, in your views use something like:
         |     @include('MyPlugin::some.view.or.partial.here')
         */
        // 'MyPlugin' => WP_PLUGIN_DIR . '/my-plugin/resources/views',
    ],

I experimented with a child-theme that has its own theme.json. that works in the sense that child theme’s theme.json overrides the generated one from the parent theme. But it’s pretty basic.

I myself need to make a number of websites that essentially use the same theme, but with slightly different styling, and with different color palettes and fonts (customizable by users). A child theme would be the Wordpress-way to do it. I am still not sure what the “Sage-way” of doing this would be (I guess the answer is: come up with your own solution;)
Should I make parent themes for all websites with only general functionality and styling and then create plugins for website-specific styling/settings/colors/fonts? It seems overly complex for what I want. Either a single customizable parent theme or the use of child themes seem like a simpler solution. Anyone who did a similar thing?

Hi all! Our team is working on moving to Sage 10 with a parent and child theme. We used to have a child theme working with a Sage 10 parent theme (Bud and Gulp combination for compiling) but since we fully moved to just the Bud compiler we’ve lost the connection to our Child theme as the assets get hashed.

I’ve read through the Discourse to find some related posts about child themes and read some comments of people who apparently found a solution but on the other hand also got a comment that it is not supported and is discouraged.

I couldn’t find the quote Matapatos sent me about not supporting child themes in Sage and it being discouraged in the Sage development ebook so I guess I’m a bit confused about this right now. This seems to be asked by quite a few people but I can’t really find a decisive answer.

My question would be:
Are child themes supported in Sage 10?

And if so:
Is there documentation on how to set up a child theme with a Sage 10 parent/child theme combination where the child theme inherits and overrules the parent theme?

Hi, and welcome. Child themes are technically supported, since Sage is just a WordPress theme like any other, but importantly Sage is a starter theme; it’s extremely bare-bones and the intent is to use it as a starting point for a custom theme build, rather than building children to it like you would with a more robust WordPress theme.

You may find yourself in a situation where you’re building one giant parent theme with Sage and then making child-themes off of it, which is a supported pattern, and you’d follow the same instructions as any other WordPress theme.

Hello Friends,
I will share my thoughts, as per my understanding regarding sage child theme.

According to eBook, about child theme : Sage is not a theme framework, it is a starter theme. You should rarely need to update it, and typically you shouldn’t create child themes from it. Being a starter theme, Sage is meant to be used as a starting point on a new project.Sage can be implemented on any sort of WordPress installation, independent of our other primary projects.

I will try to create a child theme in Sage 10 and Integrate more functionality and then I will let you know.

Thank you for your answers @MWDelaney and @dilipom13! They helped me understand it a bit more. I haven’t tried creating a child theme from a fresh install yet so I could try and get that working to see if anything is different from my current setup.

1 Like

Well, if that works that’s awesome!

Unfortunately, I had to create different themes - due to instability. I was using multisite - might cause more burden. :confused:

But let us know! :eyes: :smiley: