Knowlege base theme inheritance

Hi there,

I know there are a couple of posts on theme inheritance and the troubles most of us are running into.

My problem seems similar, but I have not found a solution to it; it refers specifically to the knowledge base theme / skeleton from @Perlkonig:

The thing is the following: after setting up the new theme, I know it works (speaking in general terms), because for example overrides in a custom.css are working and the HTML sourcecode shows that the custom.css file is loaded from the location of the new theme.

However, it seems that settings are not respected / overridden. I know I shall copy them from the original knowledge-base.yaml to the new newtheme.yaml and adding at the end the streams definitions as detailed in the documentation.

Currently, my file looks like this (being opb at the end of the file the name of the new theme):

enabled: true
dropdown:
  enabled: true

params:
  articles:
    root: /home                # the route where the articles themselves live
    blacklist: ['scratch']     # list of categories to ignore
    show:
      date: true      # show article date in the article header
      authors: true   # show article authors in the article header
      topics: true    # show assigned topics in the article header
      time: true      # show reading time in the article header
  front:              # params for the front page content
    maxrows: 3        # the maximum number of rows on the front page
    maxentries: 5     # maximum number of articles displayed for each category
  sidebar:            # params for the sidebar
    maxentries: 5     # maximum number of articles to display in "Popular" and "Latest" sections
    show:
      categories: true  # show Category list in the sidebar
      popular: true     # show the Popular Articles sidebar
      latest: true      # show the Latest Articles sidebar

streams:
  schemes:
    theme:
      type: ReadOnlyStream
      prefixes:
        '':
          - user/themes/opb
          - user/themes/knowledge-base

How do I know that settings are not inherited:

  1. because the sidebar disappears and
  2. because a dump of the configuration shows that they are not set

Switching back to the original theme (obviously) makes everything work again.

I cleared the cache and in fact disabled caching, just to make sure it had nothing to do with it.

Anyone any other idea?

Thanks in advance!
Sebastian

Hi @sklus, a long time ago I setup an inherited theme for KB… here is my YAML:

enabled: true
dropdown:
  enabled: true

params:
  articles:
    root: /home                # the route where the articles themselves live
    blacklist: ['scratch']     # list of categories to ignore
    show:
      date: true      # show article date in the article header
      authors: true   # show article authors in the article header
      topics: true    # show assigned topics in the article header
      time: true      # show reading time in the article header
  front:              # params for the front page content
    maxrows: 3        # the maximum number of rows on the front page
    maxentries: 5     # maximum number of articles displayed for each category
  sidebar:            # params for the sidebar
    maxentries: 5     # maximum number of articles to display in "Popular" and "Latest" sections
    show:
      categories: true  # show Category list in the sidebar
      popular: true     # show the Popular Articles sidebar
      latest: true      # show the Latest Articles sidebar

streams:
 schemes:
   theme:
     type: ReadOnlyStream
     prefixes:
       '':
       - user/themes/mytheme
       - user/themes/knowledge-base

Notice my first line is not in your YAML… might that be it?

Hope the above helps,
Paul
ps - if the above does not work connect with me in the Grav Discord room and I can DM you my old KB Skeleton ZIP file

Hi @paulhibbitts

Thanks for taking the time.

No unfortunately not; I just copied & pasted badly. Mi file does have that first line, too.

But thanks anyway.

Regards,
Sebastian

Hey everybody,

@paulhibbitts sent me his skeleton zip and it worked out of the box. Thanks for that! :+1:t4:

My conclusions, because in the meantime I was also reading through one of the closed issues on @Perlkonig’s GitHub:

I saw in @paulhibbitts’s zip that not only the config files were copied, but also all the twigs, although they seem identical with the ones from the original theme (I have not had a very close look :wink:). I did not do that initially.

Instead, I initially had only the new config file opb.yaml, where I tested the following:

As an example, the partials/base.html.twig from the original knowledge-base theme sets the showsidebar variable to TRUE, if grav.theme.config.params.sidebar.show.categories is set to TRUE.

When I change this line to config.themes.opb.params.sidebar.show.categories, where opb is the name of the new theme, it works and the sidebar shows up. Although I do not have any twigs in my inherited theme at all. This makes me think that the configuration file at themes/opb/opb.yaml is not read properly, when refering to it with grav.theme.config. Unless, I bring in the complete set of files from the original theme (twigs and all included). Then it reads the new config from the opb.yaml correctly. Probably because all is in the same place.

Now, when not only config, but also twigs need to be copied into the new theme, then inheritance is losing some if it’s sparkle. But I have to admit, that I do not exactly know how grav.theme.config and config.themes.opb interact and what is the proper way to go.

Anyway - a solution for my problem was found. Thanks for that! And if anyone wants to enlighten me about what I described above, even better, because then I’ll have learned something new :smiley:

Regards,
Sebastian

1 Like

Hi @sklus, just a quick follow-up that in fact those included Twigs all do contain a bit of customized Twig to support my Git Sync link in that theme. You are correct though, when using an inherited theme the customized Twig files should contain the original Twig + any of your customizations. I hope that this clarification helps🙂

It does indeed - thanks!

Even worse for me: I just did two additional tests:

  1. I took the base.html.twig out of your set of files and… it still worked :stuck_out_tongue:
  2. I copied the base.html.twig from the original theme into my not-working-theme and… it still does not work :rofl:

I’ll keep digging into it!

EDIT: I could kick myself somewhere… !

After testing, copying files, deleting them one by one, trying different template names, … it turns out I had an error in the themes/opb/opb.php file.

Embarrassing!

Sorry for bothering and thanks for the help.

No problem at all, glad you found the issue!

Does that mean, if I create a child theme, I also have to copy all of the twigs of the parent theme to my child theme?

Hi @nwi , yes that is right but only for the child theme files you want to change - copy the existing template into the corresponding inherited theme folder and then add your own customizations. All of my themes are actually inherited themes if you want to see some actual examples etc. Hibbitts Design · GitHub