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)
CODE

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>
CODE

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.
});
CODE

Parameters

Name

Type

Required

Description

configurationId

string

yes

Key of the previously created configuration to load in the configurator.

locale

string

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

HTMLElement <div>

yes

The target <div> DOM content division element where the 3D view will be rendered.

options

Object{}

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

Object{}

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

Object{}

yes

A context object.

Further reading

The Context methods reference contains a list of methods that can be called on the context object.