Back

renderText()

Instructs the controller to output plain text as the response when an action completes. Unlike rendering a view or partial, this sends the specified text directly to the client. This is especially useful for APIs, AJAX responses, or simple status messages. You can also provide an HTTP status code to control the response status.

Name Type Required Default Description
text string No The text to render.
status any No [runtime expression] Force request to return with specific HTTP status code.
1. Render a simple message
renderText("Done!");

2. Render serialized product data as JSON
products = model("product").findAll();
renderText(SerializeJson(products));

3. Render a message with a custom HTTP status code
renderText(text="Unauthorized access", status=401);

4. Use in an API endpoint
function checkStatus() {
    if (someCondition()) {
        renderText(text="OK", status=200);
    } else {
        renderText(text="Error", status=500);
    }
}
Copied!