Theme Contributor
A module that injects global CSS/JS into all themes without modifying them directly.
- Apply site-wide styling/scripts (e.g., corporate fonts, analytics).
- Maintain consistency across multiple themes.
Implementation
Section titled “Implementation”Create the Module
Section titled “Create the Module”blade create -t theme-contributor global-analyticsAdd Resources
Section titled “Add Resources”@font-face { font-family: "CorporateFont"; src: url("/o/global-analytics/fonts/CorporateSans.woff");}
body { font-family: "CorporateFont", sans-serif;}window.dataLayer = window.dataLayer || [];function gtag() { dataLayer.push(arguments);}gtag("config", "GA_MEASUREMENT_ID");Step 3: Register Resources
Section titled “Step 3: Register Resources”@Component(service = ThemeContributor.class)public class GlobalAnalyticsThemeContributor implements ThemeContributor { @Override public void contribute( ThemeRegistration themeRegistration) {
themeRegistration.addStylesheets( "/o/global-analytics/css/global.css"); themeRegistration.addScripts( "/o/global-analytics/js/analytics.js"); }}Use Cases
Section titled “Use Cases”- Corporate Branding: Enforce standard fonts/colors.
- Analytics: Add Google Tag Manager to all pages.