Code attribute not working.
Using the editor with raw html/javascript words, the editor inits just fine but when i use the template code
{{> CodeMirror id="some-id" name="someName" options=editorOptions code=editorCode reactiveVar="varName"}}
the code attribute is not passed. I get an empty editor.
The variable works fine because when I use, {{editorCode}} in the same template, it is displayed.
Try without editorCode, instead that, set reactiveVar with the initial content:
Template.yourTemplate.onRendered(function() {
Session.set("yourReactiveVarName", initialCodeToBeShownInEditor");
});
Confirmed not working.
Same issue, the code is now passed to the editor, but the editor still holds old content when you change pages.
I added this to my router to manually reload (window.location.reload()) the page in case anyone is as lost as I am:
https://pastebin.com/Vv4R1PTC
Code you gave as example does nothing with editor. Also, something is suspicious with that code (why you are reloading page?)
I know, its a workaround to refresh the DOM by refreshing the page.
I should probably clarify that the issue I am speaking about now isn't the original issue. The original issue with the "code" attribute is still not working but the work around for using the reactvie-variable is a workaround.
I am talking about another issue (which was the reason for me trying the template tag in the first place) which is when I click to the page with my editor, everything is fine in the first instance, but when I leave the page and click on a different link using the same editor template, the editor still has the information from the first page/instance. Refreshing the page itself is the only solution at the moment, hence why I posted an automatic reloader code in the router above.
I have a few more ideas to try before I give up on this.
Please show me the code which loads new content into session variable when you click to another link. Is it in template.onRendered or...?
I guess your problem is that template is actually not re-rendered (another link is at the same route with different parameter), so your onRendered code doesn't rerun. What you can do is to add Session.set(...code for editor...) into tracker (this.autorun(...) in template.onRendered and read route param here fron any reactive variable which will fire tracker's autorun.
Thanks for the reply, Here is my code
/client/editor.js
Template.editor.onRendered( function() {
this.editor = CodeMirror.fromTextArea( this.find( "#editor" ), {
lineNumbers: false,
fixedGutter: false,
mode: "markdown",
lineWrapping: true,
cursorHeight: 0.85,
addModeClass: false
});
});
/client/editor.html `
`
and the routing as per above. If there is any more relevant code you'll need, let me know.
Maybe you can see this example: https://example-ide.meteorfarm.com I don't have source code deployed but this application is generated with Meteor Kitchen and you can generate the code too, see README here: https://github.com/perak/kitchen-examples/tree/master/example-ide
I tried a few months later and found out why this code wasn't working
Template.yourTemplate.onRendered(function() {
Session.set("yourReactiveVarName", initialCodeToBeShownInEditor");
});
there was an extra " at the end. It works great now. It should be:
Template.yourTemplate.onRendered(function() {
Session.set("yourReactiveVarName", initialCodeToBeShownInEditor);
});
Lol. Thank you for your help.