javascriptace-editorcode-editor

How to add boiler-plate/default code snippet in ace.js code editor?


I am currently working on creating a code editor using ace.js. I want to add some boiler plate code every time page loads.

What I am doing till now it adding code snippet in HTML file itself like below-

<div class="editor-container">
    <div id="editor" class="w-100"># Happy Coding ... &#10;&#10;a=10&#10;b=20&#10;print("This is the sum:", a+b)&#10;</div>
</div>

I tried setting editor.innerText=code snippet, but its not working! How can I make this happen?


Solution

  • Use editor.setValue("code snippet").