Creating a subtheme from a subtheme

Creating a subtheme from a subtheme

by Ambrish Tiwari -
Number of replies: 20

Hello All,


I am using Moodle3.3 the theme I am using is Herald and I want to create a child theme based on herald as parent. Herald is child theme of bootstrapbase.  When I am trying to apply the new child theme its showing me below error

Fatal error: Class 'theme_bootstrapbase_core_renderer' not found in /var/www/html/trainingportal/theme/herald/renderers/core_renderer.php on line 8. 

I checked out the  core_renderer.php it extends theme_bootstrapbase_core_renderer but its not included in that file. 

I also went through the below link 

https://moodle.org/mod/forum/discuss.php?d=231551&parent=1022043  and added this line 

require_once( $CFG->dirroot.'/theme/bootstrapbase/renderers/core_renderer.php' );  in  core_renderer.php

but it breaking down the whole UI. The UI get disturbed. 

Can you let me know how I can fix this?


Thanks

Average of ratings: -
In reply to Ambrish Tiwari

Re: Creating a subtheme from a subtheme

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Hi Ambrish,

I will asume that you have declared bootstrapbase as the 'grandparent' in your grandchild theme's config.php in this order...?

Like so:

$THEME->parents = array('herald', 'bootstrapbase');

As for that very OLD discussion, things have changed a little and so has the code that calls the renderer.

require_once($CFG->dirroot . '/theme/bootstrapbase/renderers.php');

Also the fact you are extending the renderer in the child of a child theme makes me wonder that you may have things wrong. It could be that the code in the child theme should be extending the parent theme and NOT the grandparent, in this case bootstrapbase theme?

So try useing this line instead: ( where herald_child is your new theme's name).

class theme_herald_child_core_renderer extends theme_herald_core_renderer {

That said, however, all depends on how you have grouped the herald_child theme renderers?

They should be similar to the Clean theme, which uses the 'classes' directory.

Hope this helps?

Mary

In reply to Mary Evans

Re: Creating a subtheme from a subtheme

by Ambrish Tiwari -

Thanks Mary I was expecting you reply.

Now the child theme is seems to be working. Thanks

I have couple of query. I was with the assumption that the child theme will pick the look and feel (layout) and settings from parent theme,

But when I apply the child theme the home page has changed. I haven't written any code to override the parent theme yet in class  theme_child_core_renderer entends  theme_herald_core_renderer{ }. 

Also the breadcrumb are missing the main text instead they show the value from lang file ex( Home setting:navbarsep Courses). 

Basically I want to customise its home page. I went through https://docs.moodle.org/dev/Creating_a_theme_based_on_boost  but getting confused. 

Can you please guide me how I can achieve it. 






In reply to Ambrish Tiwari

Re: Creating a subtheme from a subtheme

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Can you let me see the config.php of your theme please, that way I can have a better idea as to how your child theme is supposed to work?

Also a screenshot of the layout of the directories belonging to this child theme?

Thanks

Mary

In reply to Mary Evans

Re: Creating a subtheme from a subtheme

by Ambrish Tiwari -

Hello Mary 

Config.php

defined('MOODLE_INTERNAL') || die();

$THEME->name = 'childtheme'; 

$THEME->doctype = 'html5';

$THEME->parents = array('herald', 'bootstrapbase');

$THEME->sheets = array();

$THEME->yuicssmodules = array();

$THEME->enable_dock = true;

$THEME->editor_sheets = array();

$THEME->rendererfactory = 'theme_overridden_renderer_factory';

$THEME->csspostprocess = 'theme_childtheme_process_css';

Directory layout is: 

root > childtheme > classes >core_renderer.php

                                 > lang>en>childtheme.php

                                 > layout  : It doesn't  have any files yet 

                                 > pix 

                                > config.php , settings.php, version.php 


In reply to Ambrish Tiwari

Re: Creating a subtheme from a subtheme

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Ok...on first look it seems fine.

However, it needs its own stylesheet if it has some settings that are different than its parent theme. It will also need a lib.php file if it has some changes from the parent theme

So how does it look? Does it look like the Herald theme?

In reply to Mary Evans

Re: Creating a subtheme from a subtheme

by Ambrish Tiwari -

Hello Mary 

The Child theme look like herald but the home page looks different the slideshow is missing and the breadcrumb navigation is not showing properly.

Currently it doesn't have any stylesheet nor lib.php. I was think that once  child theme inherits the settings from the parent and the look & feel is same as parent then I will start modifying it.

So do I have to add all the stylesheet and settings from the parent to child theme?    

 

 

In reply to Ambrish Tiwari

Re: Creating a subtheme from a subtheme

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Ok, 

Lets break this down into small bit sized pieces.

1. SETTINGS: Have you changed all the instances of theme_herald to theme_childtheme in your childtheme/settings.php? If not then please DO change them so that they work in your child theme. 

2. LAYOUT FILES: Does the Herald theme have layout files for all pages or just the Frontpage? If so then how have you coded this in the herald/config.php under $THEME->layouts = array();

In reply to Mary Evans

Re: Creating a subtheme from a subtheme

by Ambrish Tiwari -

Hello Mary,

1. Yes I have changes all the instances from theme_herald in theme_childtheme. The attached config is from theme_childtheme.

2. Herald have layout files as below. I haven't included layout files yet. And if it need to add them in theme_childtheme then I don't understand the concept of child theme / sub theme. It looks like we are creating the same theme with new name as theme_childtheme.    

theme_herald layout directory structure

In reply to Ambrish Tiwari

Re: Creating a subtheme from a subtheme

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

This line is wrong...in the config.php you uploaded

$THEME->csspostprocess = 'theme_herald_process_css';
In reply to Mary Evans

Re: Creating a subtheme from a subtheme

by Ambrish Tiwari -

Hello Mary,


I have corrected that line as $THEME->csspostprocess = 'theme_childtheme_process_css';  The  method is in lib.php which I copied from theme_herald. 

But what about the layout. For a try I copied and pasted the theme_herald layout directory in theme_childtheme but the UI is breaking down.

I see the text but page formatting is gone as if its unable to render the UI. 

   

In reply to Ambrish Tiwari

Re: Creating a subtheme from a subtheme

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

This is getting complicated, without seeing both themes it is very hard to diagnose.

Your child theme does not need any layout files yet unless there are specific things related to it, like the Carousel on the frontpage.

So just try adding the frontpage.php and any  relevant includes to the child theme changing any referance for theme_herald into theme_childtheme.

Have you Purged all caches? 

In reply to Mary Evans

Re: Creating a subtheme from a subtheme

by Ambrish Tiwari -
Hello Mary,


When I include frontpage.php its show error to include rest of the files from the include folder under layout. 


In reply to Ambrish Tiwari

Re: Creating a subtheme from a subtheme

by Ambrish Tiwari -

Hello Mary,


After changes i got my frontpage running and it look exactly like herald theme. But the problem is, I did some customisation in home-featured.php & home-slideshow.php and added these files in my theme_childtheme under layout/includes folder . Also I have added only these two files and not the other files from the theme_herald  layout folder.

But the changes are not reflecting on the frontpage.? 

Do I need to add the frontpage also in theme_childtheme and customize it too?     

In reply to Ambrish Tiwari

Re: Creating a subtheme from a subtheme

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Yes you do need to add the frontpage.php to the child theme in order that the links to those changed include files will be directed to the include files in the child theme and NOT the parent theme where it will have been looking for them at the moment.

In reply to Mary Evans

Re: Creating a subtheme from a subtheme

by Ambrish Tiwari -

Hello Mary,


The attached forntpage.php is from theme_herald. I have changed the line 44 in frontpage under theme_herald to pick the home-feature.php from childtheme and then I can see the changes. But its not the right to do it.

Can you please tell me the right way to do it?      

In reply to Ambrish Tiwari

Re: Creating a subtheme from a subtheme

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Put this back to how it was for the herald theme and  then make a copy of the original frontpage.php and add that to the childtheme/layout directory.

You only change name where you see herald, and since none exist in thet frontpage.php do not assume that you have to change it.

It justs needs to be in the childtheme layout so that it can pick up the include file that is in it's layout/includes directory. This is how themes work.

It is a complicated business and one that we have all had to learn the hardway. And this is why we tend to clone themes rather than make them child themes!

In reply to Mary Evans

Re: Creating a subtheme from a subtheme

by Ambrish Tiwari -

Thanks Mary

I appreciate your effort for me.  I will try that out and let know how it goes.

In reply to Ambrish Tiwari

Re: Creating a subtheme from a subtheme

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers
In reply to Mary Evans

Re: Creating a subtheme from a subtheme

by Ambrish Tiwari -

Hello Mary, 


The article is good, I got my couple to concepts clear regarding theme development, but still facing the problem.