-
-
Notifications
You must be signed in to change notification settings - Fork 178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sage 10 Child/Parent Theme Support #450
Comments
Regarding In the So for now I am only confused what the best way is to autload the View Composers from the parent theme. Cheers |
Well, another issue solved. Quite easy and obvious when now thinking about it: In the child theme
Furthermore if you have custom ServiceProviders in the parent theme, you need to load them as well in
So my currently only leftover is that it would be fantastic to get config values via |
Putting this on hold until Sage 10 documentation is finished. |
To chime in here from my debugging work, it looks like the current method for adding composers/components from outside the theme directory structure is no longer in The way I've found to implement composers and components is to implement theme in your child theme's ServiceProvider. Specifically, you'll want to add them into the /** ...
* Inside your ThemeServiceProvider.php file
*/
use Roots\Acorn\ServiceProvider;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\Facades\View;
...
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot() {
// Boot your view composers here.
// Note that you have to redefine the 'view' in order for it to use this composer on the correct view partials
View::composer('view.name', \ParentApp\View\Composers\ViewName::class);
// Boot your components here.
Blade::component('alert', \ParentApp\View\ComposersComponents\Alert::class);
} This is obviously not great because you have to define your view names, and import all your classes manually. Shouldn't we be able to boot the parent theme's ServiceProvider and bring in all those Composers/Components? Someone with more Laravel/PHP experience may be able to help with that. I have a feeling that if we want a child theme/app to work, we'll need to create a child theme fork. In the mean time, I hope this helps the poor souls looking to make this work. |
Does anyone have a working example of a Sage 10 parent / child theme for a noob like myself? :) |
@gitgudcameron you can have a look at this comment: ouun/stage#204 (comment) |
Thanks @evankford I was struggling with how to convert a Sage9 child-theme to Sage10 (after parent theme upgrade). I'm not 100% familiar with Blade/View/Composers yet but following your example I managed to get it working. In child theme composer file I put
To load the parent theme. I don't think it makes sense to load all components in boot so I don't mind defining each line. For example to use parents theme App I put
And child theme also uses "site messages" in
However for all the components I found "componentNamespace" in Laravel documentation which is nice so in the boot function I also put
and can use the parent themes components in the child theme like so Hope this helps anyone else making a child theme! edit Oh yeah... all the child themes View/Composers are namespaced like so |
Please let me know If I need to open a new issue for this on github? 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 the above 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
in the child App.php I have the following code
And in the child theme's
Any hint about where to go from this point will be much appreciated. |
If I understand from my troubles with this, it's likely that the child theme is not loading the parent's view composer for I'm sure there's a more elegant way to autoload all the parent's composer classes, but I add the ones I need to the boot function in the child's ThemeServiceProvider
Surely you could programmatically fetch all parent classes, or maybe I'm doing something wrong and they're supposed to be autoloaded, but this works for me. |
@evankford thank you for clearing things out for me. So, in my Parent view composer
it does not make any difference, and I still get the error that variable does not exist. |
@waqas-raza-dh Without knowing more, it's hard to say why that's not loading. I would check:
|
@evankford I was able to fix the issue. The issue was within the child stylesheet. So, composer files are loading perfectly now and all the data is also coming through. Is there any correct way of importing parent theme's styles and scripts.
|
Hello everybody! Tell me please is there any detailed guide on how to create child theme for Sage 10 properly? Can you give me the URL of such tutorial if it exists? Is this approach recommended at all? |
Hey everyone! I would like to push this discussion further ahead and hopefully, we will come up with a solution that we can incorporate into Acorn and add some official documentation about child themes. I think @ouun has a good starting point here https://github.com/ouun/stage/blob/master/app/Providers/StageServiceProvider.php#L56. I would love to just call |
@Dathix I think it's a great idea! I want to take part in this task, but I don't have enough skills to do it. I wounder what Sage core team members think about child theme support in future. |
Description
Related to this discussion: https://discourse.roots.io/t/sage-10-as-parent-child-themes/
It would be fantastic to get some feedback ftom @Log1x and @QWp6t
Steps to reproduce
1. Parent Theme:
1.1 Make a new Sage 10 Theme with custom Namespace "Parent" in folder 'parent'
1.2 Add some View Composers variables such as "siteName" and reference it in a blade file
1.3 Add a function
my_test_function()
tohelpers.php
1.4 Activate the theme, it should be working and the variable
$siteName
is outputted correctly2. Child Theme
1.1 Make a new Sage 10 Theme and leave the Namespace as "App" in folder
child
1.2 Add
Template: parent
tostyle.css
1.3 Remove all blade files from
./resources/views/
1.4 Use
\Parent\my_test_function()
e.g. in a child View Composer1.5 Autoload parent theme Class in composer.php:
1.5 Activate the child theme
Expected behavior: [What you expect to happen]
\Parent\my_test_function()
\Roots\config()
is loading parent theme value, if child theme value is not setActual behavior: [What actually happens]
Undefined variable: siteName
errors, the View Composers from the parent theme are missing\Parent\my_test_function()
\Roots\config('app.debug')
is not set in child theme as function not checks against parent valueReproduces how often: [What percentage of the time does it reproduce?]
In the current setup 100%. More tests required.
Versions
Sage 10.0.0-alpha
Additional information
It would be fantastic to get a very short summary how child/parent themes should be set-up with Sage 10.
The text was updated successfully, but these errors were encountered: