BreakParser
Replace the whole output with a message when a condition holds, without stopping the render.
break throws away everything the template has produced so far and replaces it with the payload, but the render keeps going. Tags after the break still run.
For template authors
Syntax
{break(expression):message}The parameter is an expression, written the same way as in if. The payload is the message to use as the output. Leave the payload off to end up with an empty output.
Examples
Hi {args}{break({args}==):No input given.}
# when args is empty
No input given.
# when args is "Parbez"
Hi Parbezbreak or stop?
Both replace the output, but they stop at different points.
| Tag | Later tags still run | Use it when |
|---|---|---|
{break(...):message} | Yes | You still want side effects like {delete} or {embed} to apply. |
{stop(...):message} | No | You want the render to end right there. |
For developers
Register the parser
import { Interpreter, BreakParser } from 'tagscript';
const ts = new Interpreter(new BreakParser());Behaviour
The parameter is required. {break} and {break:message} are declined, so the interpreter leaves them in the output as literal text.
parse writes to ctx.response.body and returns an empty string. Because Response.setValues keeps an already set body, whatever break wrote survives to the end of the render.
The last break whose expression is true wins, since each one overwrites ctx.response.body.
API reference
Last updated on