Creating toolbox using JSON files instead of XML files

523 views
Skip to first unread message

Hiskias Melke

unread,
Jan 21, 2021, 8:41:16 PM1/21/21
to Blockly
I was trying to create a blockly workspace using JSON files. The xml version works file since I am using Blockly.Xml.textToDom(xmlString). But I couldn't find anything on the docs to define a toolbox using JSON. There are some references as to how to make the JSON file but I couldn't inject it into the workspace. Here's the code I have, thanks!
MyBlockly.workspace = Blockly.inject('blocklyDiv',
                {
                    media: 'elevator-blockly/media/',
                    toolbox:  FunctionHere(jsonString),
                    scrollbars: true,
                    zoom:
                    {
                        controls: true,
                        wheel: false,
                        startScale: 0.8,
                        maxScale: 3,
                        minScale: 0.5,
                        scaleSpeed: 1.2,
                        pinch: false
                    },
                    renderer: 'zelos',
                    trashcan: true
                }
            );

Abby Schmiedt

unread,
Jan 22, 2021, 11:33:30 AM1/22/21
to Blockly
Hello!

Here are some docs explaining adding a json toolbox. I'm not sure what `FunctionHere(jsonString)` is doing, but whatever FunctionHere returns must be a valid json object(similar to below), a string of xml, or xml.
{
  "kind": "categoryToolbox",
  "contents": [
    {
      "kind": "category",
      "name": "Control",
      "contents": [
        {
          "kind": "block",
          "type": "controls_if"
        },
        {
          "kind": "block",
          "type": "controls_whileUntil"
        },
        {
          "kind": "block",
          "type": "controls_for"
        }
      ]
    },
    {
      "kind": "category",
      "name": "Logic",
      "contents": [
        {
          "kind": "block",
          "type": "logic_compare"
        },
        {
          "kind": "block",
          "type": "logic_operation"
        },
        {
          "kind": "block",
          "type": "logic_boolean"
        }
      ]
    }
  ]
}
 

If you continue to have problems, could you provide more information on what FunctionHere is returning? 

Cheers,
Abby
Reply all
Reply to author
Forward
0 new messages