UI RENDERING & SSR FEATURE
Resource DTOs
Real separation means templates receive one explicit response object, not loose arrays and last-minute data surgery.
Feature Guide
A quick orientation block that answers the essential questions: what this feature does, how it works, why it matters, and the key concepts behind it.
What this does
Resource DTOs are the real presentation boundary: handlers build one typed response object, and templates consume that object instead of reshaping ad hoc arrays.
How it works
A payload declares responseWith, the handler receives a concrete resource DTO, and the resource accumulates named presentation fields through with*() methods before HtmlResponse auto-renders the declared template.
Why it matters
This is real separation of data and presentation. The template stops doing data surgery, partials stop inventing their own mapping rules, and the whole view layer reads from one explicit source of truth.
Key concepts
- #[AsResource]
- Declares the template and render handle for a typed response DTO.
- HtmlResponse
- Base SSR response that stores render context and auto-renders the declared template.
- with*() methods
- Explicit resource methods that define the vocabulary of data allowed to reach the template.
Presentation Boundary
One handler shapes one Resource DTO
The shortest useful explanation is enough here: the handler receives a typed resource, fills named presentation fields, and Twig renders that finished contract.
The payload declares `responseWith`, so the handler gets a concrete Resource DTO instead of assembling loose arrays.
Presentation data is pushed through explicit `with*()` methods before Twig sees anything.
The template reads one stable response object instead of reformatting raw business data on its own.
| Resource field | Why the handler sets it |
|---|---|
title |
Page heading already shaped for the template. |
summary |
Intro copy prepared in the handler, not reconstructed in Twig. |
highlights |
Structured view data ready for repeated rendering blocks. |
resultPreviewData |
Nested preview state passed as one explicit resource field. |
Verified against Semitexa Ultimate 2026.09.19.1020
Resource DTOs
A Resource DTO is the typed presentation boundary between handler code and templates. Real separation means templates receive one explicit response object, not loose arrays and last-minute data surgery.
How it works
- The payload declares
responseWith, so the handler gets a concrete Resource DTO instead of assembling loose arrays. - Presentation data is pushed through explicit
with*()methods before Twig sees anything. - The template reads one stable response object instead of reformatting raw business data on its own.
The rules
- The Resource DTO is the response contract for templates, not a passive bucket for whatever data happened to be nearby.
- Handlers should populate presentation fields deliberately through named
with*()methods. - Twig should render data, not reinterpret domain state or normalize arrays on the fly.
- Once the resource is complete, auto-rendering can stay mechanical and reliable.
Key mechanisms
#[AsResource]— declares the template and render handle directly on the response DTO.with*()methods — create one explicit vocabulary for everything the template is allowed to consume.HtmlResponse— provides render context accumulation and automatic template rendering after the handler pipeline.
Fields prepared by the handler
| Field | Purpose |
|---|---|
title |
Page heading already shaped for the template |
summary |
Intro copy prepared in the handler, not reconstructed in Twig |
highlights |
Structured view data ready for repeated rendering blocks |
resultPreviewData |
Nested preview state passed as one explicit resource field |
How it works
A payload declares responseWith, the handler receives a concrete resource DTO, and the resource accumulates named presentation fields through with*() methods before HtmlResponse auto-renders the declared template.
Why it matters
This is real separation of data and presentation. The template stops doing data surgery, partials stop inventing their own mapping rules, and the whole view layer reads from one explicit source of truth.
Key concepts
- #[AsResource]
- Declares the template and render handle for a typed response DTO.
- HtmlResponse
- Base SSR response that stores render context and auto-renders the declared template.
- with*() methods
- Explicit resource methods that define the vocabulary of data allowed to reach the template.