### Installing and Importing a Gentelella Fork Source: https://gentelella.colorlib.com/docs/deployment How to install your fork via NPM and import its components and SCSS. Ensure the package name matches your fork's name. ```javascript npm install your-gentelella-fork ``` ```javascript import { mountShell, showModal } from 'your-gentelella-fork'; import 'your-gentelella-fork/scss/v4/main.scss'; ``` -------------------------------- ### Install Gentelella via Git Clone Source: https://gentelella.colorlib.com/docs Clone the Gentelella repository and install its dependencies to set up the project locally. This method is suitable for starting from the template. ```bash git clone https://github.com/ColorlibHQ/gentelella.git cd gentelella npm install ``` -------------------------------- ### Run the Development Server Source: https://gentelella.colorlib.com/docs Start the development server using npm. This command boots Vite with hot module replacement for live updates on SCSS, JS, and HTML changes in the src/ directory. ```bash npm run dev ``` -------------------------------- ### Build and Preview PWA Locally Source: https://gentelella.colorlib.com/docs/pwa Run these commands to build the project and preview it locally. Use this environment to verify PWA installation criteria and service worker behavior in Chrome DevTools. ```bash npm run build npm run preview ``` -------------------------------- ### Side-by-Side Deployment Structure Source: https://gentelella.colorlib.com/docs/migration-v2 Illustrates a directory structure for running both v2 and v4 builds concurrently during a migration. This setup facilitates A/B testing and phased cutovers. ```bash deploys/ ├── v2/ # current production └── v4-beta/ # new build ``` -------------------------------- ### Checkbox and Radio Button Examples Source: https://gentelella.colorlib.com/docs/forms Basic implementation for checkboxes and radio buttons using the '.form-check' class for proper styling. ```html ``` -------------------------------- ### Input with Prefix and Suffix Example Source: https://gentelella.colorlib.com/docs/forms Use the '.input-affix' class to add static text or icons before or after an input field. The leading affix should have the '.prefix' class. ```html
)
const block = document.createElement('div');
block.className = 'pg-source';
// ... see the source for the full markup
block.querySelector('.pg-code').textContent = code;
card.appendChild(block);
// Live edit, debounced 250ms
block.querySelector('.pg-code').addEventListener('input', (e) => {
clearTimeout(editTimer);
editTimer = setTimeout(() => {
preview.innerHTML = e.target.textContent;
}, 250);
});
// Copy to clipboard
block.querySelector('.pg-copy').addEventListener('click', async () => {
await navigator.clipboard.writeText(code);
showToast('Copied to clipboard', { variant: 'success' });
});
});
```
--------------------------------
### Table Initialization
Source: https://gentelella.colorlib.com/docs/typescript
Initializes tables on the page.
```APIDOC
## initTables
### Description
Initializes tables on the page.
### Signature
`initTables(): void`
### Module
`gentelella/v4/tables`
```
--------------------------------
### Build and Deploy to Cloudflare Pages with Wrangler
Source: https://gentelella.colorlib.com/docs/deployment
Build the project and then deploy the output directory to Cloudflare Pages using the Wrangler CLI. Ensure your project is configured with a build script and the output directory is set to 'dist'.
```bash
# Build, then deploy via Wrangler
npm run build
npx wrangler pages deploy dist --project-name=your-project
```
--------------------------------
### Netlify Configuration for Static Site Deployment
Source: https://gentelella.colorlib.com/docs/deployment
Configuration for Netlify's continuous deployment. Specifies the build command, publish directory, and Node.js version. Includes headers for service workers and aggressively cached assets.
```toml
[build]
command = "npm run build"
publish = "dist"
[build.environment]
NODE_VERSION = "20"
# Service-worker scope must match the deployed path
[[headers]]
for = "/sw.js"
[headers.values]
Cache-Control = "no-cache"
Service-Worker-Allowed = "/"
# Cache hashed assets aggressively
[[headers]]
for = "/js/*"
[headers.values]
Cache-Control = "public, max-age=31536000, immutable"
[[headers]]
for = "/assets/*"
[headers.values]
Cache-Control = "public, max-age=31536000, immutable"
[[headers]]
for = "/images/*"
[headers.values]
Cache-Control = "public, max-age=31536000, immutable"
```
--------------------------------
### Execute Other Project Scripts
Source: https://gentelella.colorlib.com/docs
A collection of utility scripts for analyzing bundles, capturing screenshots, linting, and formatting code. The screenshots script is used for generating README and documentation preview images.
```bash
npm run analyze Build + open the bundle treemap (rollup-plugin-visualizer)
npm run screenshots Boot Playwright + capture 44 PNGs to docs/screenshots/
npm run lint ESLint across src/
npm run format Prettier write across src/
```
--------------------------------
### Update Service Worker Cache Version
Source: https://gentelella.colorlib.com/docs/pwa
Bump the CACHE constant in sw.js on every release to invalidate the cache and ensure users get the latest version. The activate handler automatically removes old caches.
```javascript
const CACHE = 'gentelella-v4-r3'; // was 'gentelella-v4-r2'
```
--------------------------------
### Create New HTML Page for Reports
Source: https://gentelella.colorlib.com/docs/adding-pages
Drop this HTML file into the `production/` directory. Ensure the `data-page` attribute matches the key you will add to the `NAV` array in the next step.
```html
Reports | Gentelella 2026 v4
Q2 2026
Reports
Your content here
```
--------------------------------
### Disable PWA Service Worker Registration
Source: https://gentelella.colorlib.com/docs/pwa
To disable the PWA's offline support while keeping it installable, remove the service worker registration block from main-v4.js. This prevents the SW from registering but allows the manifest to still function.
```javascript
if ('serviceWorker' in navigator) {
// ... registration code to be removed
}
```
--------------------------------
### Vite Server Configuration
Source: https://gentelella.colorlib.com/docs/vite-build
Configure the development server port, proxy settings, and auto-opening behavior.
```javascript
server: {
open: '/production/index.html',
port: Number(process.env.PORT) || 9173,
host: true,
proxy: {
'/api': {
target: process.env.API_URL || 'http://localhost:8080',
changeOrigin: true
}
}
}
```
--------------------------------
### Customize DataTables Language Options
Source: https://gentelella.colorlib.com/docs/tables
Translate DataTables UI strings like search prompts, pagination labels, and info messages by modifying the `language` block in `initTables`. This example shows how to set a custom placeholder and pagination symbols.
```javascript
language: {
search: '', // No "Search:" label
searchPlaceholder: 'Search…',
info: 'Showing _START_–_END_ of _TOTAL_',
infoEmpty: 'No matching records',
infoFiltered: '(of _MAX_ total)',
zeroRecords: 'No matches found',
paginate: { previous: '←', next: '→' }
}
```
--------------------------------
### Forcing API Mode with Script Tag
Source: https://gentelella.colorlib.com/docs/data-adapter
Demonstrates how to force API mode in production by setting a global variable `window.__GENTELELLA_API__` before loading the main module.
```html
```
--------------------------------
### Scaffolding Command: v2 vs v4
Source: https://gentelella.colorlib.com/docs/migration-v2
v2 required manual edits to vite.config.js for new pages. v4 uses an auto-discovery and scaffolder system with commands like `npm run new`.
```bash
# v2 — manual edits to vite.config.js after creating production/.html
# v4 — auto-discovery + scaffolder
npm run new -- reports --title "Reports" --nav-group "Admin"
```
--------------------------------
### Data Adapter Initialization
Source: https://gentelella.colorlib.com/docs/data-adapter
Initializes the data adapter, choosing between an HTTP adapter for API calls or a seed adapter for in-memory data based on the API mode.
```javascript
const adapter = useApiMode()
? httpAdapter('/api/messages')
: seedAdapter(SEED);
```
--------------------------------
### Vercel Configuration for Static Site Deployment
Source: https://gentelella.colorlib.com/docs/deployment
Configuration for Vercel deployment. Defines the build command, output directory, and caching headers for static assets and service workers. Set framework to null if not using a specific framework integration.
```json
{
"buildCommand": "npm run build",
"outputDirectory": "dist",
"framework": null,
"headers": [
{
"source": "/(js|assets|images|fonts)/(.*)",
"headers": [
{ "key": "Cache-Control", "value": "public, max-age=31536000, immutable" }
]
},
{
"source": "/sw.js",
"headers": [
{ "key": "Cache-Control", "value": "no-cache" }
]
}
]
}
```
--------------------------------
### Verify Subpath Deployment Locally
Source: https://gentelella.colorlib.com/docs/deployment
Use the same BASE_PATH environment variable when running the preview command to test the subpath deployment locally. This ensures assets are correctly prefixed and accessible.
```bash
BASE_PATH=/admin/ npm run preview
```
--------------------------------
### Gentelella Production Build Output Structure
Source: https://gentelella.colorlib.com/docs/deployment
The `dist/` directory contains all static assets for deployment. It includes minified JS and CSS with content hashes for cache busting, static HTML pages, and other assets like fonts and images. The service worker (`sw.js`) is not hashed to ensure a stable URL.
```treeview
dist/
├── production/
│ ├── index.html # Operations dashboard
│ ├── inbox.html # Inbox client
│ ├── kanban.html # Drag-drop board
│ ├── theme.html # Live theme generator
│ ├── playground.html # Component playground
│ ├── offline.html # SW fallback
│ └── ... # 58 pages total
├── js/
│ ├── main-[hash].js # Entry chunk for index.html
│ ├── inbox-[hash].js # Lazy-loaded inbox module
│ ├── kanban-[hash].js
│ ├── vendor-echarts-[hash].js
│ ├── vendor-tables-[hash].js
│ ├── vendor-maps-[hash].js
│ └── ...
├── assets/
│ └── main-[hash].css # Compiled SCSS, one bundle
├── fonts/ # If any are self-hosted (default uses Google Fonts CDN)
├── images/
│ └── favicon-[hash].svg # ...and other content-hashed images
├── sw.js # Service worker (not hashed — needs stable URL)
├── site.webmanifest # PWA manifest
└── stats.html # Bundle analyzer treemap
```
--------------------------------
### Configure Bundle Analyzer Plugin
Source: https://gentelella.colorlib.com/docs/vite-build
This configuration snippet shows how to wire up the `rollup-plugin-visualizer` to generate a treemap of your bundle composition, which is useful for identifying unexpectedly large packages.
```javascript
plugins: [
visualizer({
filename: 'dist/stats.html',
open: false,
gzipSize: true,
brotliSize: true,
template: 'treemap'
})
]
```
--------------------------------
### Page Module Initialization
Source: https://gentelella.colorlib.com/docs/typescript
Initializes various page-specific modules.
```APIDOC
## Page Module Initialization
### Description
Initializes specific modules for different page types.
### Functions
#### initInbox
* **Description**: Initializes the inbox module.
* **Signature**: `initInbox(): void`
#### initKanban
* **Description**: Initializes the Kanban board module.
* **Signature**: `initKanban(): void`
#### initCalendar
* **Description**: Initializes the calendar module.
* **Signature**: `initCalendar(): void`
#### initFileManager
* **Description**: Initializes the file manager module.
* **Signature**: `initFileManager(): void`
#### initSettings
* **Description**: Initializes the settings module.
* **Signature**: `initSettings(): void`
```
--------------------------------
### Show a Modal with Gentelella
Source: https://gentelella.colorlib.com/docs/faq
Import and use the `showModal` function to display a modal. Ensure the DOM is ready before calling this function.
```javascript
import { showModal } from './v4/modal.js';
showModal({ title: 'Hi', body: '...', actions: [...] });
```
--------------------------------
### Show a Toast Notification
Source: https://gentelella.colorlib.com/docs/faq
Import and use the `showToast` function to display a toast message. It accepts a message and an optional configuration object.
```javascript
import { showToast } from './v4/toast.js';
showToast('Saved', { variant: 'success' });
```
--------------------------------
### Form Controls Initialization
Source: https://gentelella.colorlib.com/docs/typescript
Initializes form controls on the page.
```APIDOC
## initFormControls
### Description
Initializes form controls on the page.
### Signature
`initFormControls(): void`
### Module
`gentelella/v4/form-controls`
```
--------------------------------
### Early-Paint Theme Script
Source: https://gentelella.colorlib.com/docs/architecture
This script runs synchronously before CSS to apply the user's preferred theme (from localStorage or system preference) by setting a data-theme attribute on the html element. It includes error handling for localStorage access.
```html
```
--------------------------------
### Check Node.js and npm Versions
Source: https://gentelella.colorlib.com/docs
Verify that your Node.js and npm versions meet the requirements for Gentelella v4.0.0. Node.js 20 or higher and npm 10 or higher are recommended.
```bash
node --version # v20.0.0 or higher
npm --version # 10.0.0 or higher
```
--------------------------------
### Build for Subpath Deployment
Source: https://gentelella.colorlib.com/docs
Configure the build process to deploy under a specific subpath by setting the BASE_PATH environment variable.
```bash
BASE_PATH=/admin/ npm run build
```
--------------------------------
### Access Demo Pages via CDN
Source: https://gentelella.colorlib.com/docs
Directly access the 58 built demo pages of Gentelella v4 through jsDelivr CDN. These URLs point to the production-ready HTML files.
```html
https://cdn.jsdelivr.net/npm/gentelella@4/dist/production/index.html
```
```html
https://cdn.jsdelivr.net/npm/gentelella@4/dist/production/inbox.html
```
```html
https://cdn.jsdelivr.net/npm/gentelella@4/dist/production/kanban.html
```
--------------------------------
### Auto-discover Vite Entries
Source: https://gentelella.colorlib.com/docs/vite-build
This function scans the 'production/' directory for HTML files to use as build entries. It maps 'index.html' to 'main' for backward compatibility and uses filenames for other entries.
```javascript
function discoverEntries() {
const dir = resolve(import.meta.dirname, 'production');
const out = {};
for (const file of readdirSync(dir)) {
if (!file.endsWith('.html')) continue;
// index.html → chunk name 'main' (kept for backwards compat);
// everything else uses the filename stem.
const stem = file === 'index.html' ? 'main' : file.replace(/\.html$/, '');
out[stem] = `production/${file}`;
}
return out;
}
// ...later in defineConfig:
rollupOptions: {
input: discoverEntries(),
// ...
}
```
--------------------------------
### Observe Theme Changes
Source: https://gentelella.colorlib.com/docs/echarts
Sets up a MutationObserver to watch for changes to the `data-theme` attribute on the `` element and listens for a custom `themechange` event. Both trigger a `rebuild()` function to update charts.
```javascript
const themeObserver = new MutationObserver((records) => {
if (records.some((r) => r.attributeName === 'data-theme')) rebuild();
});
themeObserver.observe(document.documentElement, { attributes: true, attributeFilter: ['data-theme'] });
document.documentElement.addEventListener('themechange', rebuild);
```
--------------------------------
### seedAdapter - In-Memory Data Adapter
Source: https://gentelella.colorlib.com/docs/data-adapter
The `seedAdapter` creates an in-memory data store initialized with provided data. It supports filtering and mutations, with a `reset` method to restore the original seed. Useful for testing and development.
```APIDOC
## `seedAdapter` — in-memory
```javascript
import { seedAdapter } from './v4/data-adapter.js';
const SEED = [
{ id: 1, subject: 'Welcome', folder: 'inbox', unread: true },
{ id: 2, subject: 'Q3 review', folder: 'inbox', unread: false }
];
const adapter = seedAdapter(SEED, (item, query) => {
if (query.folder) return item.folder === query.folder;
return true;
});
await adapter.list(); // → both items
await adapter.list({ folder: 'inbox' }); // → both (filter passes)
await adapter.update(1, { unread: false });
await adapter.list(); // → item 1 is now unread:false
adapter.reset(); // back to original seed
```
The optional second arg is a filter function `(item, query) => boolean` so the seed can mimic backend query params (folder, status, search). Mutations are persistent for the page lifetime but not across reloads. `adapter.reset()` restores the original seed — useful for testing.
```
--------------------------------
### Command Palette Operations
Source: https://gentelella.colorlib.com/docs/typescript
Functions for initializing and controlling the command palette.
```APIDOC
## Command Palette Functions
### Description
Provides functions to initialize and control the command palette interface.
### Functions
#### initCommandPalette
* **Description**: Initializes the command palette.
* **Signature**: `initCommandPalette(): void`
* **Module**: `gentelella/v4/command-palette`
#### openCommandPalette
* **Description**: Opens the command palette.
* **Signature**: `openCommandPalette(): void`
* **Module**: `gentelella/v4/command-palette`
#### closeCommandPalette
* **Description**: Closes the command palette.
* **Signature**: `closeCommandPalette(): void`
* **Module**: `gentelella/v4/command-palette`
```
--------------------------------
### Use Data Attributes for Per-Instance Chart
Source: https://gentelella.colorlib.com/docs/echarts
Provide per-instance data and styling for a custom chart by setting 'data-points' and 'data-color' attributes on the host element.
```html
```
--------------------------------
### REST Backend with httpAdapter
Source: https://gentelella.colorlib.com/docs/data-adapter
The `httpAdapter` facilitates interaction with a REST backend. It maps standard CRUD operations to HTTP requests. The default fetch implementation can be customized.
```javascript
import { httpAdapter } from './v4/data-adapter.js';
const adapter = httpAdapter('/api/messages');
await adapter.list({ folder: 'inbox' });
// GET /api/messages?folder=inbox
// → response body parsed as JSON
await adapter.get(1);
// GET /api/messages/1
await adapter.create({ subject: 'Hi' });
// POST /api/messages with JSON body
await adapter.update(1, { unread: false });
// PATCH /api/messages/1 with JSON body
await adapter.remove(1);
// DELETE /api/messages/1
```
```javascript
const adapter = httpAdapter('/api/messages', { listKey: 'messages' });
const items = await adapter.list(); // extracts data.messages
```
```javascript
const authedFetch = (url, opts = {}) => fetch(url, {
...opts,
headers: { ...opts.headers, Authorization: `Bearer ${TOKEN}` }
});
const adapter = httpAdapter('/api/messages', { fetch: authedFetch });
```
--------------------------------
### Conditional Data Fetching Logic
Source: https://gentelella.colorlib.com/docs/data-adapter
Shows how to use the `useApiMode` hook to conditionally execute code for hitting a real backend or using seed data.
```javascript
import { useApiMode } from './v4/data-adapter.js';
if (useApiMode()) {
// hit real backend
} else {
// use seed
}
```
--------------------------------
### Force Light Mode in HTML
Source: https://gentelella.colorlib.com/docs/faq
Apply this script to force the light theme. Place it after the pre-paint script in the head section of your HTML.
```html
```