Visitar URL original
Customization · YAFNET/YAFNET Wiki · GitHub
Skip to content
Ingo edited this page Nov 14, 2026 · 7 revisions

Create a custom theme or modify an existing one

YAF.NET v4 themes are based on Bootstrap 5 and Bootswatch. A theme is written in Sass (SCSS) and compiled to one CSS file, plus two HTML email templates that are styled the same way.

There are two ways to build a theme:

How themes work

At runtime a theme is a folder in the web root of the forum:

wwwroot/css/themes/[theme]/
├── bootstrap-forum.min.css     the compiled theme (Bootstrap + forum styles)
├── EmailTemplate.html          template for all emails
└── DigestTopicTemplate.html    template for one topic in the digest email
  • Every folder in wwwroot/css/themes/ is listed as a theme. The folder name is the theme name.
  • The board theme is selected in Admin > Board Settings > Theme (default: yaf).
  • If Admin > Host Settings > Allow users to change theme is enabled, each user can select a theme in My Settings.
  • The light/dark mode selector in the forum header uses the Bootstrap color modes, so a theme should look good in both modes.

Important

All three files are required. Emails are sent with the EmailTemplate.html of the theme, and without it no email can be sent.

Theme source files

A theme is a folder with these source files:

File Description
_variables.scss Bootstrap variables of the website: colors, fonts, spacing, border radius...
_bootswatch.scss Extra styles of a Bootswatch theme (not in the yaf theme)
bootstrap-forum.scss Main file of the website CSS: imports the variables, Bootstrap and the forum styles
_variables-email.scss Variables of the email templates (only yaf, the Bootswatch themes use _variables.scss for the emails too)
bootstrap-email.scss Main file of the email CSS
bootstrap_email.json bootstrap-email config for EmailTemplate.html (source build only)
bootstrap_email-digest.json bootstrap-email config for DigestTopicTemplate.html (source build only)

bootstrap-forum.scss of the yaf theme:

@import "_variables.scss";

@import "bootstrap/scss/bootstrap";

@import "forum/chat.scss";

@import "choices/bs-theme.scss";
@import "netStack.scss";

The Bootswatch themes also import _bootswatch.scss right after Bootstrap. Keep the imports of chat.scss, bs-theme.scss and netStack.scss: they contain the styles of the chat, the select boxes and the forum controls.

Note

Up to YAF.NET 4.0.10 the themes import these files with relative paths (@import "../../../../node_modules/bootstrap/scss/bootstrap";, @import "../../forum/chat.scss";...). To use such a theme with the theme kit, change the imports as shown above.

Change the style

  • Change the variables in _variables.scss, e.g. the primary color, the font and the border radius:

    $blue:    #3761b5 !default;
    $primary: $blue !default;
    
    $font-family-sans-serif: "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif !default;
    $border-radius:          .5rem !default;

    All variables with their default values are in Bootstrap's _variables.scss (node_modules/bootstrap/scss/_variables.scss after npm install). The dark mode colors are in _variables-dark.scss (the variables ending in -dark, e.g. $body-bg-dark).

  • Add your own CSS rules at the end of bootstrap-forum.scss (or in _bootswatch.scss), after the Bootstrap import, so you can use the Bootstrap variables and mixins:

    .card-header {
        background-color: tint-color($primary, 80%);
    }
  • For the emails, change the colors in _variables-email.scss (yaf theme) or _variables.scss (Bootswatch themes).

Create a theme with the theme kit

The npm package @yafnet/theme-kit contains the sources of all themes included in YAF.NET, the forum styles the themes need, and the command line tool yafnet-theme.

Important

Use the kit with the version of your forum, e.g. @yafnet/theme-kit@4.0.11 for YAF.NET 4.0.11. The themes contain the styles for the forum markup and the Bootstrap version of a release.

Requirements

  • Node.js 20 or newer

  • Optional, for the email templates in the colors of your theme: the .NET SDK and the bootstrap-email tool:

    dotnet tool install --global BootstrapEmail.Net.Cli

    Without bootstrap-email the kit uses the prebuilt email templates of the theme you started from (with its colors).

Create and build a theme

  1. Create a folder for your theme project and install the kit:

    mkdir my-forum-theme
    cd my-forum-theme
    npm init -y
    npm install --save-dev @yafnet/theme-kit@4.0.11
  2. Create the theme, here mytheme as a copy of the Bootswatch theme cosmo (without --from the yaf theme is used):

    npx yafnet-theme new mytheme --from cosmo

    npx yafnet-theme list shows all themes you can start from. The theme is created in the folder themes/mytheme.

  3. Change the style in themes/mytheme/.

  4. Build the theme:

    npx yafnet-theme build

    The theme is written to dist/mytheme/ (bootstrap-forum.min.css, EmailTemplate.html, DigestTopicTemplate.html).

  5. Deploy the theme and select it in Admin > Board Settings > Theme.

Commands

Command Description
npx yafnet-theme list Lists the themes of the kit you can start from.
npx yafnet-theme new <name> [--from <theme>] Creates the theme <name> in the themes folder as a copy of a theme of the kit (default: yaf).
npx yafnet-theme build [<name>...] Builds all themes in the themes folder, or the named ones.
npx yafnet-theme watch [<name>...] Builds the CSS again whenever a file in the themes folder changes.
Option Description
--themes <folder> Folder of the theme sources (default: themes).
--out <folder> Output folder (default: dist).
--no-email build: only the CSS, not the email templates.

Tip

To see your changes while you work, run a local forum and build directly into its theme folder, then reload the page after each change:

npx yafnet-theme watch mytheme --out C:\inetpub\yaf\wwwroot\css\themes

Update to a new YAF.NET version

Install the kit of the new version and build your theme again, so it gets the styles of new forum features and Bootstrap updates:

npm install --save-dev @yafnet/theme-kit@<new version>
npx yafnet-theme build

Build themes in the YAF.NET source code

Requirements

  • The YAF.NET source code of the same version as your forum, e.g. from the releases (Source code (zip)) or with git:

    git clone --branch v4.0.11 https://github.com/YAFNET/YAFNET.git
  • Node.js (LTS version) to compile the CSS.

  • Only for the email templates: the .NET SDK and the bootstrap-email tool:

    dotnet tool install --global BootstrapEmail.Net.Cli

Run all commands below in the yafsrc/YetAnotherForum.NET folder. Install the Node.js packages once:

npm install

You don't need to build the forum itself (no Visual Studio, no dotnet build) to build a theme.

Folder Content
wwwroot/lib/themes/[theme]/ SASS sources of the theme. Edit these files.
wwwroot/css/themes/[theme]/ Compiled CSS and email templates. Generated by the build, don't edit them.
wwwroot/resources/ EmailTemplate.html and DigestTopicTemplate.html before they are styled.

Modify an existing theme

Note

Always modify the SASS files, never the compiled CSS. The CSS files are overwritten by the next build, and a theme included in YAF.NET is replaced by the next update. For changes you want to keep, create a new theme instead.

  1. Change the style in wwwroot/lib/themes/[theme]/.

  2. Compile the CSS:

    npm run css

    This compiles the CSS of all themes in wwwroot/lib/themes/ to wwwroot/css/themes/[theme]/bootstrap-forum.min.css.

  3. If you changed the email colors, build the email templates:

    npm run emailTemplates

    This builds the templates of all themes and takes a while. To build the templates of one theme only, run bootstrap-email yourself:

    bootstrap-email -f wwwroot/resources/EmailTemplate.html -d wwwroot/css/themes/[theme]/EmailTemplate.html -c wwwroot/lib/themes/[theme]/bootstrap_email.json
    bootstrap-email -f wwwroot/resources/DigestTopicTemplate.html -d wwwroot/css/themes/[theme]/DigestTopicTemplate.html -c wwwroot/lib/themes/[theme]/bootstrap_email-digest.json
  4. Deploy the theme.

Create a new theme

The example creates the theme mytheme from the yaf theme (plain Bootstrap). To start from a Bootswatch theme, copy that folder instead, e.g. cosmo.

  1. Copy the folder wwwroot/lib/themes/yaf to wwwroot/lib/themes/mytheme. Use a folder name without spaces.

  2. Replace the old theme name with the new one:

    • bootstrap_email.json and bootstrap_email-digest.json, the setting sass_email_location:

      "sass_email_location": "wwwroot/lib/themes/mytheme/",
    • bootstrap-email.scss, the import of the email variables:

      @import '../themes/mytheme/variables-email';

      ('../themes/mytheme/variables' if you copied a Bootswatch theme)

  3. Change the style.

  4. Build the CSS and the email templates:

    npm run css
    bootstrap-email -f wwwroot/resources/EmailTemplate.html -d wwwroot/css/themes/mytheme/EmailTemplate.html -c wwwroot/lib/themes/mytheme/bootstrap_email.json
    bootstrap-email -f wwwroot/resources/DigestTopicTemplate.html -d wwwroot/css/themes/mytheme/DigestTopicTemplate.html -c wwwroot/lib/themes/mytheme/bootstrap_email-digest.json

    The build finds new theme folders by itself, no build file needs to be changed.

  5. Check that wwwroot/css/themes/mytheme/ contains bootstrap-forum.min.css, EmailTemplate.html and DigestTopicTemplate.html.

  6. Deploy the theme and select it in Admin > Board Settings > Theme.

Tip

To see your changes while you work on the theme, start the forum from the source (dotnet run in yafsrc/YetAnotherForum.NET, see Build with Command Line), select your theme and reload the page after each npm run css.

Deploy the theme

Copy the theme folder (dist/[theme]/ of the theme kit, or wwwroot/css/themes/[theme]/ of the source) into the folder wwwroot/css/themes/ of your forum. The forum doesn't need a restart, the theme is listed in the theme selection right away.

  • IIS / Linux: copy the folder into the wwwroot/css/themes folder of the published forum.

  • Docker: the themes are part of the image. Mount your theme folder into the container, e.g. in docker-compose.yml:

    volumes:
      - ./mytheme:/app/wwwroot/css/themes/mytheme:ro

Note

An update of YAF.NET replaces the themes included in YAF.NET, but not your own theme folder. Keep the sources of your theme somewhere safe, and build it again for the new version after an update.

Troubleshooting

Problem Solution
The theme is not listed in the theme selection The folder must be directly in wwwroot/css/themes/ of the running forum.
No emails are sent after the theme was selected EmailTemplate.html or DigestTopicTemplate.html is missing in the theme folder. Build them, or copy them from another theme for a start.
Can't find stylesheet to import Source: run npm install first. Theme kit: a theme of YAF.NET 4.0.10 or older imports Bootstrap and the forum styles with relative paths, change the imports as shown in Theme source files.
bootstrap-email fails with Could not find a part of the path '...\tools\...\wwwroot\lib\bootstrap-email\templates\body.html' Version 1.7.x of the tool looks for the files in its own folder. Install the current version: dotnet tool update --global BootstrapEmail.Net.Cli.
The changes are not visible in the browser The browser caches the CSS. Reload the page with Ctrl+F5.

Clone this wiki locally