var toolbox =
'<xml xmlns="http://www.w3.org/1999/xhtml" id="toolbox" style="display: none">' +
// Sep line removed
' <category name="DM" colour="#a55b80" id="testblock">' +
' <block type="whole_tts">' +
' <field name="dm">hello</field>' +
' <field name="dm1">0</field>' +
' <field name="dm2">0</field>' +
' </block>' +
' </category>' +
'</xml>';
workspace = Blockly.inject('blocklyDiv', {toolbox: toolbox }) workspace = Blockly.inject('blocklyDiv', options);
// All toolbox-specific XML has been removed.
var xml_text =
'<xml xmlns="http://www.w3.org/1999/xhtml" id="toolbox" style="display: none">' +
' <block type="whole_tts">' +
' <field name="dm">hello</field>' +
' <field name="dm1">0</field>' +
' <field name="dm2">0</field>' +
' </block>' +
'</xml>';
var xml = Blockly.Xml.textToDom(xml_text);
// Where workspace is the above workspace var
Blockly.Xml.domToWorkspace(xml, workspace);
console.log(workspace.id);function start() {
// All of the URL parsing...
// Create main workspace.
workspace = Blockly.inject('blocklyDiv',
{
// etc...
});
addToolboxButtonCallbacks();
// This call added.
appendDom();
// etc...
}
function appendDom() {
var blocks = document.getElementById('workspace-blocks');
if (blocks.firstElementChild) {
Blockly.Xml.appendDomToWorkspace(blocks, workspace);
}
}
<xml id="workspace-blocks" xmlns="http://www.w3.org/1999/xhtml" style="display: none">
<!-- my blocks here -->
</xml>Hi Beka,Thanks for helping.Actually I'm trying to design a game and want to load the contents according to the levels.Different levels will have different configurations.So yes i need to load my workspace with some predefined blocks and my tool box according to different levels.To do so, I was thinking to make diff Directories and load content according to those is it possible??
Also, I created a seperate div as <div id="blocklyDiv1" style="height: 400px"></div> where i want to load my workspace and toolbox but when i do so, I get two seperate div container.How can i load my content into blockly's Workspace??Please help....Following is my Html code<body><div id="blocklyDiv1" style="height: 400px"></div><table width="100%" height="100%"><tr><td><h1><a href="https://developers.google.com/blockly/">Blockly</a>‏ ><a href="../index.html">Demos</a>‏ ><span id="title">...</span></h1></td><td class="farSide"><select id="languageMenu"></select></td></tr><tr><td colspan=2><table width="100%"><tr id="tabRow" height="1em"><td id="tab_blocks" class="tabon">...</td><td class="tabmin"> </td><td id="tab_javascript" class="taboff">JavaScript</td><td class="tabmin"> </td><td id="tab_python" class="taboff">Python</td><td class="tabmin"> </td><td id="tab_php" class="taboff">PHP</td><td class="tabmin"> </td><td id="tab_lua" class="taboff">Lua</td><td class="tabmin"> </td><td id="tab_dart" class="taboff">Dart</td><td class="tabmin"> </td><td id="tab_xml" class="taboff">XML</td><td class="tabmax"><button id="trashButton" class="notext" title="..."><img src='../../media/1x1.gif' class="trash icon21"></button><button id="linkButton" class="notext" title="..."><img src='../../media/1x1.gif' class="link icon21"></button><button id="runButton" class="notext primary" title="..."><img src='../../media/1x1.gif' class="run icon21"></button></td></tr></table></td></tr><tr><td height="99%" colspan=2 id="content_area"></td></tr></table><div id="content_blocks" class="content"></span></div><pre id="content_javascript" class="content"></pre><pre id="content_python" class="content" ></pre><pre id="content_php" class="content"></pre><pre id="content_lua" class="content"></pre><pre id="content_dart" class="content"></pre><textarea id="content_xml" class="content" wrap="off"></textarea>
<category name="Text" colour="#a55b80" id="testblock"><block type="whole_tts"><field name="TTSDEFAULT">hello</field><field name="TTSLOOP">0</field><field name="TTSTIME">0</field></block></category></xml><script>$(document).ready(function() {var toolbox = document.getElementById("toolbox");var options = {toolbox : toolbox,collapse : false,comments : false,disable : false,maxBlocks : Infinity,trashcan : false,horizontalLayout : false,toolboxPosition : 'start',css : true,rtl : false,scrollbars : false,sounds : true,oneBasedIndex : true};workspace = Blockly.inject('blocklyDiv1', options);var xml_text ='<xml xmlns="http://www.w3.org/1999/xhtml" id="workspace_1" style="display: none">' +' <block type="whole_tts">' +' <field name="dm">hello</field>' +' <field name="dm1">0</field>' +' <field name="dm2">0</field>' +' </block>' +'</xml>';var xml = Blockly.Xml.textToDom(xml_text);Blockly.Xml.domToWorkspace(xml, workspace);});</script>