> 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/helpers.md).

# Helpers

The package exposes a small helper layer for rendering and view-related convenience tasks.

## `view()`

```php
function view(): View
```

Use this as the normal entry point.

```php
view()->setLayout('layouts/main');
```

Behavior:

* resolves the View service through `ViewFactory::get()`
* returns the shared `View` instance for the current DI container

Because the instance is shared, helper calls see the same layout and param state.

## `partial()`

```php
function partial(string $partial, array $args = []): string
```

This is a shortcut for `view()->renderPartial()`.

```php
$card = partial('partials/user-card', ['user' => $user]);
```

Use it when you need a fragment without the full page pipeline.

## `view_param()`

```php
function view_param(string $key)
```

Reads one value from the current view param bag.

If the key does not exist, it returns `null`.

## `raw_param()`

```php
function raw_param($value): RawParam
```

Creates a `RawParam` wrapper for trusted content.

```php
view()->setParam('body', raw_param($trustedHtml));
```

Prefer this when a value should stay unescaped but you do not want to call `setRawParam()` directly.

## `markdown_to_html()`

```php
function markdown_to_html(string $content, bool $sanitize = false): string
```

Converts Markdown to HTML with `league/commonmark`.

```php
$html = markdown_to_html($markdown);
$safeHtml = markdown_to_html($markdown, true);
```

Contract:

* always converts Markdown first
* when `$sanitize` is `false`, returns the converted HTML as-is
* when `$sanitize` is `true`, runs the converted HTML through HTML Purifier before returning it

Important caveat:

* sanitizing is opt-in, not the default
* this helper is independent from the View package's param escaping pipeline


---

# 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/helpers.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.
