News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

Comprehending "Theme Variants"

Started by James Gryphon, July 01, 2016, 02:19:37 AM

Previous topic - Next topic

James Gryphon

I've been struggling to try to get an implementation of 2.0's theme variants working, and've just been beating my head against the wall, getting more and more frustrated, so I thought I might as well drop in here and see if somebody could clue me in.

I've been using a heavily modified version of Core, split up into two different themes, one with different backgrounds for some boards, the other with a uniform look. It didn't take long to dawn on me that installing or uninstalling mods on Core-based themes that are not actually Core is a colossal pain. So, I wanted to include the alternate appearance directly inside the main theme as a theme variant. The manual seemed to indicate it shouldn't be that hard if the CSS was already written.

I should've known it couldn't be that easy.

The guide on multi-style themes says:
QuoteNormally, CSS files are called from the index.template.php file, like so:

<link rel="stylesheet" type="text/css" href="', $settings['theme_url'], '/style.css?b4" />
To enable multiple styles to be selected for the one theme, the following should be used instead:


<link rel="stylesheet" type="text/css" href="', $settings['theme_url'], '/style', $context['theme_variant'], '.css?b4" />

Instant problem: none of the stuff in Core looks exactly like that. Nary a trace of ".css?b4" to be seen. I figured that since the part that had changed was the part after "$settings['theme_url'], I could include the '/style'... bit after that, though, up to where the differences stopped, and it would probably be fine.

Another problem: which part should be changed? Should I go through every single code segment that references $settles['theme_url'], or just the one at the top, or what? After lots of tinkering and various problems, I gave up and downloaded Dilber, and it seemed like I should only do the first one, so I went ahead with that. Dilber features this code, but everything else related seemed to be the same:
// The ?fin20 part of this link is just here to make sure browsers don't cache it wrongly.
echo '
<link rel="stylesheet" type="text/css" href="', $settings['theme_url'], '/css/index.css?fin20" />
<link rel="stylesheet" type="text/css" href="', $settings['theme_url'], '/css/index', $context['theme_variant'], '.css?fin20" />';

I tried adding the first line from this code in my file. With it, my mod does at least display some sort of theme, but it doesn't vary a bit regardless of what variant it's set to, in spite of my having three index files with _suffixes. Also, the expanding/closing images on the front page are all broken (and stayed that way even after I added folders in the Image folder, with duplicate versions of the same image files since there are no theme-specific icons) named after the variants, like I'd seen in Dilber). Without the first line of that code, there's no CSS at all and I get a white, unformatted page.

As an aside, the theme variant names are broken. They show up with umlauted ö's surrounding them. I thought this might have something to do with the legendary ThemeStrings.english.php file, which is alluded to in the manual... but it turns out that in spite of a seemingly promising snippet referring to "Theme Strings in Themes", that section of the guide never actually covers how to make one of those, and there aren't any examples already included in the default theme. I tried to hack one up, but all the forum did was give me errors about not having slashes next to single quote marks (another problem that got me more than a little ticked off, since I couldn't tell how it was any different from any of the other code I'd been reading), so finally I gave up and I skipped it. Dilber's didn't have anything to do with anything that it looked like I might need, so I hoped it wouldn't make a difference. Who knows whether it does or not.

Every change I make seems to either preserve the defective status quo or make things worse, and it looks like I inadvertently broke the entire forum right before I left by overwriting the regular, non-experimental forum theme's Index.template.php file with a copy that gave users single-quote errors and didn't give them any other theme to use instead. I've fixed that, but my patience with this code is rapidly deteriorating. I haven't the faintest clue why it doesn't work when the limited information in the manual and the other themes I've looked at seem to give every indication that it ought to.

I could prattle on about all my symptoms for ages, but I thought it would be a lot easier to just upload a file of the defective theme here, so that people who really care about it can get to the trouble and cut me, the middleman, out of it. If I don't understand what the problem is I probably wouldn't be any better at communicating what I did to it anyway.

Hopefully somebody who knows what they're doing can explain how this has gone so horribly wrong. I've given it my best shot and I just don't have any idea.

James Gryphon

Well, as usual I come off feeling foolish, but at at least it got resolved.

I played with it some more. As usual it turned out that the error was a stupid little thing, in this case what I consider an act of sabotage by my previously trusted TextEdit.

I tried my hand at making another ThemeStrings file... as it turns out, TextEdit had been automatically inserting "smart quotes" in the files, absolutely wrecking everything. ::) Once I fixed that, the trouble cleared right up.

Chalk up another one for proofreading, I guess.

Advertisement: