Web SDK Reference - Create context from configuration
window.twikbot.createContextFromConfiguration
loads the configurator, sets the initial value based on an existing configuration and initializes a context object that can be used to interact with it.
window.twikbot.createContextFromConfiguration(configurarationId, locale, target, options, startupParameters)
Example usage
Add a canvas and parameters element to your HTML file and call the createContext() method to initialize the configurator.
HTML
<div id="myCanvas"></div>
<div id="myParameters"></div>
JavaScript
let productKey = 'wheel';
let locale = ''; // Name of your translations file. Empty string if no translations are available.
let target = document.getElementById("myCanvas");
let context = window.twikit.createContextFromConfiguration(configurationId, locale, target , {
loaded: function() {
// Called when the context finished loading.
},
parametersReady: function(parameterContainer) {
// Called when parameter HTML elements are ready.
// 'parameterContainer' is a <div> element with parameter HTML elements contained in it.
document.getElementById("parameters").appendChild(parameterContainer);
},
parameterDataReady: function(parameters) {
// Called when parameter data is ready.
// 'parameters' is an array of parameter data.
},
statusChanged: function(progress, status) {
// Called while loading the context to report progress.
// 'progress' is the progress percentage, an integer number between 0 and 100.
// 'status' reports the loading state, either 'loading', 'ready' or 'failed'.
console.log(progress + '%');
},
variationChanged: function(variation) {
// Called when variation changed.
console.log('variation changed', variation);
},,
twikbotContextReady: function(internalTwikbotContext) {
// called when the internal context is ready
internalTwikbotContext.numericComponent$.subscribe(numbers => console.log('number outputs : ', numbers));
// an observable (rxjs) that list latest version of numeric outpu components if applicable in the product
},
previewBackgroundColor: '#eeeeee' // Used to set the background color of the 3D canvas.
});
Parameters
Name | Type | Required | Description |
---|---|---|---|
configurationId |
| yes | Key of the previously created configuration to load in the configurator. |
locale |
| yes | The locale to use when loading the configurator. Maps with the locales defined in https://cms.twikit.com, default value if no translations are available ‘default’. |
target |
| yes | The target |
options |
| no | Object to pass to the create context function. The object allows to register callback functions to get updates and provide additional settings such as the background of the canvas. |
startupParameters |
| no | Object with parameter settings to use when starting the configurator. This can be used to enable or disable parameter options given a startup value. E.g. In a car configurator, a limited set of interior colors is available given a preselected exterior car color. |
Returns
Type | Required | Description |
---|---|---|
| yes | A context object. |
Further reading
The Context methods reference contains a list of methods that can be called on the context object.