Skip to main content
Topic: Question about theme layers  (Read 5254 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Re: Question about theme layers

Reply #15

You can probably use the integrate_theme hook and check there to see if the theme matches the one you want then add a temporary hook via the add_integration_hook function.


Re: Question about theme layers

Reply #16

Quote from: Bloc – I've seen from the source code that adding Theme.php inside the custom theme apparantly makes Elkarte use that..and that seems to be interesting as a way to customize the theme engine(possibly), but it still calls the Templatelayers.class which seems not be fecthed from anywhere else that Sources anyway.
If you think about it, the moment you have access to swap the parent object, you are basically in control of anything that happens inside of it, so you can just replace the theme class with one of your own and instantiate a Templates class of your choice picked from wherever you want.

Quote from: Bloc – I am kind of deterred by the fact the subtemplates is not so easily managed by the theme in Elkarte. I mean, I see the reasons for it, but it does limit what a theme could do. You are kind of stuck with the order they are presented in. But I acknowledge that there is probably not a high demand for it ...other than for myself :) ..so I guess its a non-priority. I'll keep tugging at it until I find a work-around because I think Elkarte is by far the better of all forked SMF scripts, including SMF(2.1) itself.   
TBH I'm kind of confused here.

If you read the code I presented you above, you have all the answers you need already: you can get the list of layers/subtemplates, you can remove them, you can add them. Do you need anything else?
When adding, you have all the options and flexibility of the Priority class, so you can add (at the) "beginning", (at the) "end", after or before another one, you can specify a level of priority (not if after/before, of course), etc.
You can do anything you want and be way less concerned by side-effects than you are with a simple array. shrugs
Worst case, you can even remove everything and insert only whatever you want, basically killing any addon that would be brave enough to provide an interface for adding some content, just because you want your theme to be the only ruler of the game.
If this is not freedom I'm not sure what it is.
Bugs creator.
Features destroyer.
Template killer.

Re: Question about theme layers

Reply #17

Well, thank you for providing a way with adding this to layers - I am not ungrateful for that. I am however, confused as to how to do it..after all, I am not at the coding level you guys are.  :(

But to adress one of your arguments: I am not at all trying to take control over everything in the theme, including any brave addon's attemtps at providing an interface. I just want to be able to at least be aware over whats coming so the theme can take steps to theme that in any way possible. I find it fun to experiment with designs and thats why I asked for guidance to be able to do that.

But I am less interested nowadays to fight for this.... so I'll just acknowledge its hard to do in Elkarte and move on. 


Re: Question about theme layers

Reply #18

I think what @emanuele is saying is that’s it’s the opposite of hard, it’s actually quite easy. You have an template layers object which you can query and manipulate how ever you see fit. It’s not an array, but that makes it more powerful and useful as you can easily inject or remove segments without needing to rebuild your array.

I’m struggling to see where you’re not understanding so it’s hard to explain, but the current implementation (imo) is very powerful and will allow you to do anything you want.

Re: Question about theme layers

Reply #19

I make sure I ask in here if I am confused of anything in theming or coding addon as I am also more to a not so advanced user of Elkarte.

So far it is really easy to theme or code with Elkarte, once you understand it of course, if compared to its predecessor.

If I were as good as you @Bloc, I may even make plenty of wonderful themes with Elkarte.

As for age, yeah, I am also feeling old as well, and FYI I just ceased practising as an advocate and solicitor in Malaysia after 20 years.

So I know what you mean by no more figthing, but that doesn't mean I cannot change, learn or adapt.

I am now a director of my own IT Services private limited company, or so to say, I also changed, learned and adapted.

The only similarities between the two services and the businesses, I used logic and common sense to make them work for me.

So good luck in whatever you choose to endeavour @Bloc.

Re: Question about theme layers

Reply #20

Ahrasis, learning new things is not the problem for me..

Using the word "fight" is probably not best word to use here, its nothing to be upset about - I, and probably most people here, do this in our leisure time and in that case choose actively to learn and use it(Elkarte or SMF scripts that is).

Yeah, it may be indeed easy to accomplish this(relatively speaking). But if the functionality of being able to change layer positions from the theme - or even just see the layer positions and subseqently the subtemplate ordering - is not there in a straight-forward way its clearly not something themes are meant to do in the first place. 

For me it means an obstacle that will prevent me from creating a theme the way I envision it, that is all.

Re: Question about theme layers

Reply #21

Sorry @Bloc, I don’t see how it’s not there in an easy to see way. You take the object and read the data back, if you want you can turn that into an array locally manipulate that how you want it then write it back to the object. It’s all contained within one ‘item’ which can be used how you see fit.

Re: Question about theme layers

Reply #22

@tino , emanuele gave me a code example that means using a hook, preferably the integrate_buffer hook. Well, to be painfully aware of my own limitations: how the heck do I do that from the theme? template_init function? Tried that, did not work.

Its probably not hard to do this from any source file, but I 'd like to do it from the theme itself - so to not 1) turning the theme into a addon/mod 2) keep theme separated (although arguably I don't by doing it this way anyway) from Sources code and files.

As mentioned before, my intention is not to make the theme "the ruler of all".(but I can see that may be what you think, based on my objections towards themes before, mostly in SMF. Though again, there too, I never meant themes should tell Sources what to do, rather have a little more freedom in deciding what goes where. Not what goes *nowhere*..) Being able to make choices on the layout that cannot be done through CSS alone gives that freedom.

Re: Question about theme layers

Reply #23

I don’t think you want to theme to be ruler of all, I can largely grasp what you’re trying to do.

I’ve not done any theme development work really other than playing with css and changing the layers and pointing them to my own layer instead. So it’s slightly different.

Can you send me what you have so far? Or even a small template of what you’re trying to achieve. I’ll have a play and see if I can get it working.

Re: Question about theme layers

Reply #24

If I add this
Code: [Select]
add_integration_function('integrate_buffer' , 'TestHook', __FILE__, false);

To template_init in the index.template.php function it appears in my hook list and get's executed as I would expect. Although that hook is probably a bit late for you to do anything with the template order.

Re: Question about theme layers

Reply #25

You mentioned integrate_theme hook earlier...will that execute early enough to inject a new layer(or sidebar code as emanuele suggested)? I am not at home atm, but will test more once I get there. Thanks! :)

Re: Question about theme layers

Reply #26

Honestly I don’t know, that’s where I have to hand over to @Spuds  or @emanuele.

You really want the one just before the templates are called and rendered. It does appear you can add them from a theme only though, which is good.

Re: Question about theme layers

Reply #27

Will the custom theme index.template be loaded when the hook is executed I wonder...or can you add a path to index.template.php within the add_integration_function call?  I am thinking to add the hook code there.

Re: Question about theme layers

Reply #28

The template_init seems to be run quite early in the execution path. So you’d want to aim for just before the _above template is called, I’d think.

The FILE points to the current file btw, so in this instance it's the file I edited index.template.php.
Last Edit: February 26, 2021, 11:42:08 am by tino

Re: Question about theme layers

Reply #29

The hook code itself is a function I assume - but I get a blank page when just adding it. If the function does not exist, all is fine..

So the hook code/function must perhaps do something or return something specific? (I am so out of tune on hook code lol)