Configurator & presets variable
  • 28 Nov 2022
  • 2 Minutes to read
  • Contributors
  • Dark
    Light

Configurator & presets variable

  • Dark
    Light

Article Summary

Everything you create in the configurator editor is either directly or indirectly connected to your configurator. With the configurator variable you can access all these things and additional information about your configurator.

Properties

namedescription
isDraftwill be true inside a draft and false in a published configurator
startUrlthe URL for starting a new configuration based on the default preset
componentsa map of all the components you have created

You can access these properties like so: configurator.IsDraft

Accessing components

In addition to the properties above, you can also access any of your components with the configurator variable. For example, configurator.Price would refer to a "price" component. Of course, you can also just write price to work with that component – usually.

You may end up in a situation where something else is also called "price" and simply writing price will return that thing. This can happen for example in a graphic component, when you give one of your visuals the name "price". Inside that component, "price" will then refer to your visual and not the price component. To fix that problem, you can write configurator. Price to get to your component.

Super special case: if you end up in a situation where something else is called configurator, the solution above won't work. You can't use the configurator variable because that other thing is also called "configurator".

The best way to avoid this problem is not to call anything "configurator" – but in case you have to, there's a special keyword to help you out: @top. This rarely used keyword is always reachable and enables you to access things "at the top", like the configurator variable. For example, @top.configurator.Price will always refer to the "price" component, no matter what.

Presets

You can work with the presets that you have created for your configurator by using the presets variable. Similar to configurator, you can access any preset by name by writing presets.MyPreset (where "MyPreset" is the name you've given your preset). However, in this case the presets variable is mandatory – "MyPreset" alone will not return your preset.

Additionally, the presets variable has these built-in properties:

namedescription
currentreturns the preset on which the current configuration is based
defaultreturns the default preset of your configurator
allreturns a map of all the presets you have created

Once you have obtained a preset, you can use its properties:

namedescription
idthe unique identifier of this preset
startUrlthe URL for starting a brand-new configuration based on this preset

Example

To get the URL to start a new configuration based on the same preset as the current configuration:

presets.Current.StartUrl
Just like configurator, the presets variable also lives "at the top" – meaning you can use @top.presets to always reach it, even if something else is called "presets".

Was this article helpful?