Controller
renderText()
Signature
Section titled “Signature”renderText() — returns void
Available in: controller
Category: Rendering Functions
Description
Section titled “Description”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.
Parameters
Section titled “Parameters”| 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. |
Examples
Section titled “Examples”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);
}
}