> For the complete documentation index, see [llms.txt](https://quantumphp.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://quantumphp.gitbook.io/docs/packages/view/architecture.md).

# Architecture

The View package sits on top of Renderer and coordinates the rest of the page-rendering pipeline.

## Main components

### `View`

`Quantum\View\View` owns request-time rendering state:

* the current layout file
* accumulated view params
* layout asset definitions collected through `setLayout()`
* the last rendered page body from a full page render

It does not resolve template files itself. It always delegates the final template render to `Renderer`.

### `ViewFactory`

`ViewFactory::get()` is the standard entry point.

It resolves the view service through DI and memoizes one `View` instance inside the factory. In practice, repeated `view()` calls during the same container lifecycle return the same object.

That shared-instance behavior matters because layout, params, and layout asset definitions are mutable state, not one-shot method arguments.

### `RawParam`

`RawParam` is the package's explicit escape hatch.

If a param is wrapped in `RawParam`, the View package skips HTML escaping for that value and returns the original payload to the renderer.

## Full render flow

`render()` follows this sequence:

1. require a layout to be set
2. merge any runtime params into the existing param bag
3. render the page view through the renderer
4. register layout assets, if any were attached through `setLayout()`
5. update debugger route metadata when the debugger is enabled
6. render the layout through the renderer
7. optionally cache the final layout HTML by request URI when view cache is enabled

The body view renders before the layout. Layout templates can then read the rendered body through `getContent()`.

When view cache is enabled, the package still renders the page and layout first. It then stores the final HTML under the current request URI and returns the cached copy for that URI.

## Partial render flow

`renderPartial()` is deliberately smaller.

It merges params into the shared param bag and renders the requested file. It does not require a layout and does not trigger asset registration, debugger updates, or view-cache writes.

## Escaping boundary

Before each render, the package recursively escapes strings with `htmlspecialchars(..., ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8')`.

Practical effect:

* normal strings are safe by default for HTML output
* nested arrays are escaped too
* object properties are escaped in place
* raw values must be marked intentionally

Because object properties are updated during filtering, do not pass reusable mutable objects if you need to preserve their original string values elsewhere.

## Integration points

The package relies on other packages for surrounding concerns:

* Renderer: template adapter and file lookup
* Asset: registers layout assets before layout render
* Debugger: records the rendered view path when enabled
* ResourceCache: caches final layout output by request URI


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://quantumphp.gitbook.io/docs/packages/view/architecture.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
