sjs-4e

Embedded JavaScript engine, a dialect of sjs-4 that is similar to PHP.

sjs-4e

Embedded JavaScript engine, a dialect of sjs-4 that is similar to PHP.

Description

Embed JavaScript code into HTML similar to PHP. The code will be transpiled to sjs-4 before being executed, thus you can use the API of the sjs-4 engine.

Source mapping is not implemented yet. When an error is encountered, the row will be reported correctly, while the column (char position) will be incorrect.

Syntax

There are only a couple of syntax elements to be aware of:

  • Embed JS code: <? ... ?>,
  • escape and print the value of foo: <?= foo ?>,
  • print the value of foo (unescaped raw html): <?== foo ?>,
  • print to the output buffer within JS code blocks: print().

Examples

Example without JS code.

Multiline example without JS code.

Write HTML escaped output to the output buffer.

Write raw unescaped output to the output buffer.

Comment.

Embed JS for control flow, no output.

You can call print() to write to the output buffer.

Closing tag is optional.

Empty code block is fine.

Printing <? and ?>.

The line number is reported correctly, the column number incorrectly.

Spaces must be used between <? and the comment block.

Subscribe to our newsletter!