q2a / question2answer

Question2Answer is a free and open source platform for Q&A sites, running on PHP/MySQL.
http://www.question2answer.org/
GNU General Public License v3.0
1.63k stars 627 forks source link

Is it possible to extend a theme? #971

Closed nmeri17 closed 1 year ago

nmeri17 commented 1 year ago

I'm having trouble modifying sections of the code controlled by SnowFlat theme from my plugin. The theme just calls $this->method, instead of delegating to the layer stack which would cause my layer to run. It isn't documented that theme defined methods will have precedence over whatever is written in a layer class

Anyway, I want to convert my layer into a theme, but without overriding all the styling of SnowFlat. Unfortunately, it just enables my new theme but doesn't seem to execute its qa-theme class. At the top of it, I have

require_once QA_INCLUDE_DIR . "../qa-theme/SnowFlat/qa-theme.php";

use qa_html_theme as SnowFlat;

class qa_html_theme extends SnowFlat {
    // my methods
}

The above neither works nor throws any error. I can't var_dump but I know the class doesn't run since it throws no error when I put a deliberately wrong path

How do I fix this?

svivian commented 1 year ago

Hi, sorry for the late reply.

It isn't documented that theme defined methods will have precedence over whatever is written in a layer class

That's not true - or at least it shouldn't be. If you make a layer plugin the function in the plugin will run instead of the one in the theme. However if you have multiple layers, one may override another. In your layer you should call parent::method(); if you want to append to the theme's content.

In the general case, there isn't a way to extend themes. The only way is to duplicate the theme entirely and change what you need.