loadVariables
Category: Variable Management
Namespace: web.variables.loadVariables
Description
Loads variables from a file saved with saveVariables(). Merges with existing variables (overwrites duplicates).
Syntax
// Load from default file
await web.variables.loadVariables();
// Load from a specific file (positional string argument)
await web.variables.loadVariables('app_variables.txt');
Parameters
- fileName (optional) - File path to load variables from (relative or absolute). If omitted, uses the default application variables file.
⚠️ Note: The argument is a positional string, not an options object. Use
loadVariables('file.txt')notloadVariables({ fileName: 'file.txt' }).
Returns
Promise - Resolves with a message indicating how many variables were loaded
Examples
Simple example (default file)
await web.variables.loadVariables();
console.log('Variables loaded');
Load on startup
// Load saved variables when app starts
document.addEventListener('DOMContentLoaded', async () => {
await web.variables.loadVariables();
// Apply loaded settings — NOTE: getVar uses positional string arg
const theme = await web.variables.getVar('theme');
if (theme) {
applyTheme(theme);
}
});
Import settings from user-selected file
// Let user import settings from file
const filePath = await web.dialogs.openFile({
title: 'Import Settings',
fileTypes: 'Variable Files (*.txt)|*.txt|All Files (*.*)|*.*'
});
// openFile returns a string path, or "" if cancelled
if (filePath) {
await web.variables.loadVariables(filePath);
alert('Settings imported successfully');
}
Use Cases
- Restore variables on application startup
- Import settings from backup
- Load saved application state
- Implement settings import feature
- Restore user preferences
Notes
- File must be in key=value format (created by
saveVariables()) - Merges with existing variables — overwrites duplicates
- Skips empty lines and lines starting with
#(comments) - Uses UTF-8 encoding
- Relative paths are resolved from application directory
- Returns count of variables actually loaded