News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

One custom theme pulling templates from another?

Started by Antechinus, September 29, 2014, 07:21:00 PM

Previous topic - Next topic

Antechinus

Hey just wondering if this is possible. Like if you made a theme and wanted to pull a pile of templates from an earlier custom theme, rather than including them all over again in the new one. So the fallback chain would be "Look in newest theme" else "Look in older custom theme" else "Fall back to default".

Can do? No can do? Bonkers? Pigs can fly?

Arantor

Sure. It's fragile as sin but it's possible.

In the bowels of theme_info.xml, you can define <based-on>. If used during installation, this will look up the theme_dir, theme_url and images_dir of the theme in question and make those available.

When loadTemplate subsequently fires, it adds $settings['base_theme_dir'] (i.e. the directory for the theme on which the current theme is based) to the list, so it checks current theme, then base theme if it exists, then default theme.

The value of <based-on> should be the folder name of the theme from which you are trying to inherit.

Antechinus

Yeah I was wondering what that did. I suppose with 2.0.x doing auto install of mods on all themes there's not much point, since it's extra db shiz to process and you'd only really be saving a few hundred kb of storage space on the server.

Arantor

DB stuff is fairly negligible, the auto installation is definitely a consideration of course, but I can certainly see the appeal if you have a lot of heavily customised templates but it almost sounds like bordering on variantism if you're not careful.

(FWIW I had to look up what <based-on> did since I've never had occasion to use it)

Antechinus

Yeah I just remembered what prompted this. I like the Apocalypse templating, but a lot of it is so custom it would break mod installation (depending on the mod etc) so that would mean manual edits anyway, or writing your own xml, which is much the same amount of work. So in that case only having to do said edits once would be a bonus, if some nutter were to use those templates as a basis for other themes.

And yeah, variants is a point too. However, some nutter had the idea of using variants for markup switching.* :D

*Haz actually done this before and it works a treat.

Arantor

Yes but based-on still only works if you're installing two things on one site where they're sharing templates, which almost no themes actually ever do any more (there's some that inherited templates from Core, though)

In the situation you're referring to it's quite different.

Antechinus

Hey here's one for you: ever heard of a way to using media queries to trigger php conditionals? That would be awesome powerful but I don't think it can be done.

Arantor

It can't as such because the media conditionals are only inside the browser, nothing gets sent to the server with them. Of course it wouldn't be outside of the realm of possibility to have the server sent PHP-driven CSS files and do different things based on the different requests being made, but that's icky and not really something in the scope of SMF (and not recommended for performance reasons)

Antechinus

Yeah I thought so. Responsive design is good in some ways and crap in others. Tends to make for very sub-optimal markup on at least some devices, and for very verbose and convoluted css (which all has to be served all the time).

*IOW, responsive is bad for performance anyway

live627

Phones are getting faster nowadays, so extra hidden markup isn't much an issue anyway.

Arantor

The considerations you give it are ones I don't even tend to worry about personally because I can show you so many ways to break CSS performance when you start worrying about tag reflows with AJAX excitement. It's been a long, long time since CSS performance was a serious concern for me...

You should see Discourse. That's what pain looks like, doubly so on mobile.

Antechinus

#11
Quote from: live627 on September 29, 2014, 08:25:02 PM
Phones are getting faster nowadays, so extra hidden markup isn't much an issue anyway.

Hmm. Well if that's the case, it'd probably make sense to start wrapping chunks of markup in parents that can be dealt with by media queries. Example would be shunting all the poster info around on phones. The CSS gets to be a PITA, so rather than frigging around trying to mutate the contents of the desktop poster area, just display: none; the whole shebang and have a second one that is marked up for phone (and is also display: none; above a certain res).

Point being you'd have more markup sitting around picking its nose, but could keep your CSS easier to deal with (fewer fried brain cells). You can do just about anything with CSS, but sometimes markup changes really make more sense.

ETA: I think I might try this idea.

Advertisement: