bricks_import_variables
Overview
Imports global CSS variables from JSON or CSS format into the Bricks site. Supports two modes: « merge » keeps existing variables and adds or updates new ones, while « replace » overwrites all variables with the imported set.
This tool enables design system portability between Bricks sites. Use it to transfer design tokens from staging to production, share a standard design system across projects, or restore variables from a backup.
Key Features
When to Use
Restoring variables from a JSON backup after a failed refactor
Bootstrapping a new site with a standard design token set
Importing design tokens from a CSS file or third-party design tool
Syncing variable changes from staging to production
When NOT to Use
When updating a single variable — use bricks_update_global_variable
When you just need to read the current variables — use bricks_get_global_variables
Parameters
modestringoptionalmerge Values: merge, replacevariablesarrayoptionalcategoriesarrayoptionalcssstringoptionalCode Examples
Import from JSON Export (Merge)
Import variables exported from another site, keeping existing variables intact.
bricks_import_variables({
mode: "merge",
variables: [
{ name: "spacing-xs", value: "4px", category: "cat1" },
{ name: "spacing-sm", value: "8px", category: "cat1" },
{ name: "spacing-md", value: "16px", category: "cat1" }
],
categories: [
{ id: "cat1", name: "Spacing" }
]
}){"success": true, "data": {"imported": 3, "skipped": 0}, "message": "Imported 3 variables (merge mode)"}Import from CSS String
Import variables from a plain CSS custom properties string.
bricks_import_variables({
mode: "merge",
css: "--spacing-xs: 4px; --spacing-sm: 8px; --spacing-md: 16px; --spacing-lg: 24px; --spacing-xl: 32px;"
}){"success": true, "data": {"imported": 5, "skipped": 0}, "message": "Imported 5 variables from CSS (merge mode)"}Replace All Variables
Replace the entire variable set with a new one from an export. WARNING: This removes all existing variables.
bricks_import_variables({
mode: "replace",
variables: [
{ name: "spacing-xs", value: "4px", category: "cat1" },
{ name: "spacing-sm", value: "8px", category: "cat1" }
],
categories: [{ id: "cat1", name: "Spacing" }]
}){"success": true, "data": {"imported": 2, "skipped": 0}, "message": "Replaced all variables with 2 imported variables"}Common Mistakes
// Oops — replaces ALL variables, not just adds new ones
bricks_import_variables({ mode: "replace", css: "--new-var: 10px;" })// Safe: merge keeps existing variables
bricks_import_variables({ mode: "merge", css: "--new-var: 10px;" })bricks_import_variables({ css: "spacing-xs: 4px; spacing-sm: 8px;" })bricks_import_variables({ css: "--spacing-xs: 4px; --spacing-sm: 8px;" })Tips & Warnings
Always export before replacing: Use bricks_export_variables({ format: "json" }) to create a backup before using « replace » mode.
Merge is safer: « merge » mode only adds new variables or updates existing ones with matching names. It never deletes existing variables.
CSS import loses categories: When importing from CSS, variables are created without category assignments. For organized imports, use the JSON format with categories.
Pair with export: The typical workflow is: bricks_export_variables on site A, then bricks_import_variables on site B.