Skip to content

[3.0] Load the stylesheet a theme variant is recoloured with - #9669

Open
albertlast wants to merge 1 commit into
SimpleMachines:release-3.0from
albertlast:3.0/theme-variant-stylesheet
Open

albertlast wants to merge 1 commit into
SimpleMachines:release-3.0from
albertlast:3.0/theme-variant-stylesheet

Conversation

@albertlast

@albertlast albertlast commented Sep 9, 2026

Copy link
Copy Markdown
Collaborator

Description

A theme has two ways to recolour a variant, and Theme::loadVariant() only implements one of them.

The first is a single variants.css holding :root[data-variant="…"] blocks. That one is loaded.

The second is a whole stylesheet per variant sitting on top of index.css. The default theme documents it in index.template.php, right above the setting that declares the variants:

	/*
	 * Define the theme variants. Each variant has its own CSS file.
	 *
	 * Example:
	 * - index_red.css is loaded when the user selects the `red` variant.
	 *
	 * Additionally, a variants.css file is always loaded as well, in
	 * case you'd rather keep the styles in a single file or they're minimal.
	 */

and again further down:

			The most efficient way of writing multi themes is to use a master
			index.css plus variant.css files. If you've set them up properly
			(through Theme::$current->settings['theme_variants']), the variant files will be loaded
			for you automatically.

Nothing loaded them. This adds it.

Details
  • order_pos is 2 — after index.css at 1 and beside dark.css, so the variant sheet overrides the base sheet, which is the point of it.
  • The default variant is the base sheet on its own, so it has no file and is skipped.
  • loadCSSFile() validates by default, so a theme that recolours through variants.css instead simply has nothing queued. Adding this cannot break such a theme.
  • The default theme declares no variants, so nothing changes for it.
Verification

Declaring a sunset variant in the default theme locally, all three cases on a running forum with nothing added to log_errors:

case result
index_sunset.css present, ?variant=sunset loaded — its marker rule appears in the minified bundle
index_sunset.css absent, ?variant=sunset nothing queued, page 200, nothing logged
index_default.css present, ?variant=default correctly skipped

Issues References (Fixes|Related|Closes)

Related to #7933.

🤖 Generated with Claude Code

A theme has two ways to recolour a variant. One is a single variants.css
holding :root[data-variant="..."] blocks, which loadVariant() already loads.
The other is a whole stylesheet per variant, sitting on top of index.css,
which the default theme documents in index.template.php:

	Define the theme variants. Each variant has its own CSS file.

	Example:
	- index_red.css is loaded when the user selects the `red` variant.

Nothing loaded it. The file goes in at order_pos 2, after index.css and
beside dark.css, so it overrides the base sheet. The 'default' variant is
the base sheet by itself and has no file to load; for any other variant the
file is validated before it is queued, so a theme that recolours through
variants.css instead is unaffected.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Signed-off-by: albertlast <mathiaspapealbert@hotmail.com>
@albertlast albertlast mentioned this pull request Sep 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant