Extension:TemplateStylesExtender

Other languages:
MediaWiki extensions manual
OOjs UI icon advanced-invert.svg
TemplateStylesExtender
Release status: stable
Implementation Parser extension
Description Extends Extension:TemplateStyles with new selectors
Author(s) Octfxtalk
Latest version 1.0.2 (2021-09-06)
MediaWiki 1.35+
PHP 7.2+
License GNU General Public License 2.0 or later
Download

  • $wgTemplateStylesExtenderEnablePrefersColorScheme

Check usage and version matrix.

The TemplateStylesExtender extension extends Extension:TemplateStyles with new selectors and matchers.

FeaturesEdit

  • Add support for CSS variables
    • Example color: var( --color-base )
  • Add support for image-rendering
  • Add support for ruby-position
  • Add support for ruby-align
  • Add support for scroll-margin-* and scroll-padding-*
  • Add support for @media (prefers-color-scheme: dark/light) media queries

InstallationEdit

  • Download and place the file(s) in a directory called TemplateStylesExtender in your extensions/ folder.
  • Add the following code at the bottom of your LocalSettings.php:
    wfLoadExtension( 'TemplateStyles' );
    wfLoadExtension( 'TemplateStylesExtender' );
    
  • Configure as required.
  •   Done – Navigate to Special:Version on your wiki to verify that the extension is successfully installed.

ConfigurationEdit

Key Description Example Default
$wgTemplateStylesExtenderEnablePrefersColorScheme Flag to enable @media (prefers-color-scheme: dark/light) media queries false true
$wgTemplateStylesExtenderEnableCssVars Flag to enable css vars false true

Note CSS VarsEdit

Currently using :root selectors won't work due to template styles prepending .mw-parser-output.

One possible fix is to wrap the entire content into a `div` element and adding the declarations to this, e.g.

div#content-wrap {
   --padding: 10px
}

.content {
   padding: var( --padding )
}

Wikitext

<div id="content-wrap">
   <div class=".content">
      The WikiText...
   </div>
</div>

See alsoEdit