I do not suggest trying to go around the standard render pipeline, so there are two ways, using functions, to output that I'd recommend.
- Using output in <<script>>.
- Returning a string to one of the <<print>> variants. Obviously, you cannot use this to output DOM elements, so this is only useful when you're able to output strings—e.g. plain text or markup.
FUNCTIONS : Using output in <<script>>
Using the <<script>> macro, you simply need to use output. For example:
<<script>>
$(output).wiki("Cry 'Havoc!', and let slip the //ponies// of ''friendship''.");
<</script>>
To do that from within a function, you'll have to pass output into the function somehow. There are a couple ways to do that.
- Pass it in as a parameter:
setup.letSlip = function (out) {
$(out).wiki("Cry 'Havoc!', and let slip the //ponies// of ''friendship''.");
};
Usage:
<<script>>setup.letSlip(output)<</script>>
- Invoke the function via <Function>.call() or <Function>.apply() and set the function's this to output:
setup.letSlip = function () {
$(this).wiki("Cry 'Havoc!', and let slip the //ponies// of ''friendship''.");
};
Usage:
<<script>>setup.letSlip.call(output)<</script>>
NOTE: This technique will not work with ES6 arrow functions, as they have an intrinsically bound this.
I listed #2 solely for the sake of completeness, you probably don't want to use that method.
FUNCTIONS : Returning a string to one of the <<print>> variants
Write your function to return a string. For example:
setup.letSlip = function () {
return "Cry 'Havoc!', and let slip the //ponies// of ''friendship''.";
};
Usage:
<<= setup.letSlip()>
MACROS
Macros do have access to the render buffer. Whether or not you choose to write JavaScript macros, rather than widgets or functions, is up you to. If that's what you decided to do, then you'd, obviously, need to become familiar with the Macro API.
As an example of the same thing I showed above, but done as a macro:
Macro.add('letslip', {
handler : function () {
$(this.output)
.wiki("Cry 'Havoc!', and let slip the //ponies// of ''friendship''.");
}
});