MojoPad

Scripting: Scriptlets

Scriptlets are little pieces of JavaScript embedded in a page that run when the page is exported, previewed, or used as a template. The syntax is VoodooPad's:

<% writer.write('Hello from a scriptlet') %>
<%= new Date().getFullYear() %>

The = form writes the expression's value; the plain form runs statements and writes whatever you pass to writer.write(). (In this manual the tags are typeset so they won't run; in your pages, just type them normally.)

The scriptlet environment

ObjectMeaning
writer.write(s)append output where the scriptlet stands
destinationweb, pdf, epub, page, preview, or template — vary output by where it's going
page.namethe page being rendered

Errors render inline in red rather than breaking the export. Scriptlets run during every export, HTML preview, and template instantiation — they're how a page can contain the current date, a computed table, or different footers for web and PDF.