Theme Controller
TsgcHTMLThemeController / TsgcHTMLThemeBuilder — manage light, dark and system themes across all pages and generate Bootstrap CSS variable blocks for custom brand colours.
TsgcHTMLThemeController / TsgcHTMLThemeBuilder — manage light, dark and system themes across all pages and generate Bootstrap CSS variable blocks for custom brand colours.
TsgcHTMLThemeController reads a cookie or query parameter to determine which Bootstrap theme to activate and injects the required initialisation script. TsgcHTMLThemeBuilder generates a <style> block that overrides Bootstrap CSS variables with your brand colours.
TsgcHTMLThemeController, TsgcHTMLThemeBuilder
Light/dark theming & custom CSS
Delphi, C++ Builder, .NET
Use TsgcHTMLThemeController to read a cookie or query parameter and apply the correct Bootstrap theme attribute. Use TsgcHTMLThemeBuilder to emit a custom CSS variable block for your brand colours.
uses
sgcHTML_ThemeController;
// Detect theme from request cookie:
var
oTheme: TsgcHTMLThemeController;
begin
oTheme := TsgcHTMLThemeController.Create(nil);
try
oTheme.CookieName := 'app_theme';
oTheme.DefaultTheme := htSystem;
// Inject into the Bootstrap template:
oTemplate.HeadContent :=
oTemplate.HeadContent + oTheme.GetThemeScript(ARequest);
finally
oTheme.Free;
end;
end;
// Generate brand CSS variables:
var
oBuilder: TsgcHTMLThemeBuilder;
begin
oBuilder := TsgcHTMLThemeBuilder.Create(nil);
try
oBuilder.PrimaryColor := '#7C3AED';
oBuilder.SecondaryColor := '#1E293B';
oTemplate.HeadContent :=
oTemplate.HeadContent + oBuilder.Build;
finally
oBuilder.Free;
end;
end;
TsgcHTMLThemeController *oTheme = new TsgcHTMLThemeController(NULL);
try
{
oTheme->CookieName = "app_theme";
oTheme->DefaultTheme = htSystem;
oTemplate->HeadContent += oTheme->GetThemeScript(ARequest);
}
__finally { delete oTheme; }
TsgcHTMLThemeBuilder *oBuilder = new TsgcHTMLThemeBuilder(NULL);
try
{
oBuilder->PrimaryColor = "#7C3AED";
oTemplate->HeadContent += oBuilder->Build();
}
__finally { delete oBuilder; }
var themeCtrl = new TsgcHTMLThemeController();
themeCtrl.CookieName = "app_theme";
themeCtrl.DefaultTheme = TsgcHTMLTheme.htSystem;
template.HeadContent += themeCtrl.GetThemeScript(request);
var themeBuilder = new TsgcHTMLThemeBuilder();
themeBuilder.PrimaryColor = "#7C3AED";
template.HeadContent += themeBuilder.Build();
The members you reach for most often.
Name of the cookie that stores the user's theme preference (htLight / htDark / htSystem).
Fallback theme when no cookie or query parameter is present.
Reads the active theme from the request (cookie or ?theme= parameter) and returns the Bootstrap theme initialisation script to inject into <head>.
Overrides Bootstrap's --bs-primary CSS variable with your brand colour.
Raw CSS custom-property declarations appended to the generated <style> block for any Bootstrap or app-level variable.
Returns a <style> block containing the :root overrides; assign to TsgcHTMLTemplate_Bootstrap.HeadContent.
| Online HelpFull API reference and usage guide for this component. | Open | |
| All sgcHTML ComponentsBrowse the full feature matrix of 60+ components. | Open | |
| Download Free TrialThe 30-day trial ships the 60.HTML demo projects. | Open | |
| PricingSingle, Team and Site licenses with full source code. | Open |