How can I invoke the c3ml parsing engine?


I have a component configuration that I want to be “c3ml enabled” so that the users of the component can configure complex logic into the config.

I would like to be able to configure something like this:
*.c3ui file

"srcType": "{{'Turbine') > -1 ? 'AircraftTurbine' :'Radar') > -1 ? 'AircraftRadar' : etc ... etc ... }}" 

*.js file

srcType =  C3MLEngine.parse(this.get('srcType'))

Is there such an API that would do what Im trying to do in C3MLEngine.parse



There is no single entry point for the C3ML engine, but it can be invoked by first creating a C3.script.Program and then a C3.script.Evaluation for that program. You’ll find that the documentation and features are very poor, even your example doesn’t work with current C3ML implementation as it uses .indexOf('Turbine') instead of a UIHelper function.

Since “simple” use cases like this are not supported I would advise against exposing the engine from a component field as users will not get proper error messages nor documentation.

Instead of exposing the full C3ML engine, you could formally describe your type name mappings in an object and then the c3ui file would look like this:

"srcTypeMappings": {
  "Turbine": "AircraftTurbine",
  "Radar": "AircraftRadar",

"srcType": "{{ }}"

Then use the matchDynamicContent helper in your js file:

var dynamicContent = this.get("srcType"),
    pageParams = this.get(''),
    resolvedTypeName = C3.script.helpers.matchDynamicContent(
        this, dynamicContent, pageParams,
        null, this.get("environment"))
    c3TypeName = this.get("srcTypeMappings")[resolvedTypeName];


Thanks for the detailed response, Juan. The proposed solutions doesn’t quite work for my use case because I need to manipulate the value a bit before using it as a lookup in a hash map.

Specifically, I would like to do use a helper function to split the string like so: {{ strRight(, "_") }}, where is something like "A001_23G00". When I tried feeding that “dynamicContent” to the matchDynamicContent API, it simply returned the exact same string. Is this expected?



matchDynamicContent doesn’t support function calls, only field access