# View

> View represents a view object in the MVC pattern.

[API reference](/docs/api/index.md) › [yii](/docs/api/yii/index.md) › [web](/docs/api/yii/web/index.md) › View

| class | `yii\web\View` |
| --- | --- |
| Extends | [`yii\base\View`](/docs/api/yii/base/view/index.md) » [`yii\base\Component`](/docs/api/yii/base/component/index.md) » [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| Implements | [`yii\base\DynamicContentAwareInterface`](/docs/api/yii/base/dynamiccontentawareinterface/index.md), [`yii\base\Configurable`](/docs/api/yii/base/configurable/index.md) |
| Since | 2.0 |
| Source | [`framework/web/View.php`](https://github.com/yiisoft/yii2/blob/22.0/framework/web/View.php#L59) |

View represents a view object in the MVC pattern.

View provides a set of methods (e.g. [`render()`](/docs/api/yii/base/view/index.md#method-render)) for rendering purpose.

View is configured as an application component in [`Application`](/docs/api/yii/base/application/index.md) by default.
You can access that instance via `Yii::$app->view`.

You can modify its configuration by adding an array to your application config under `components`
as it is shown in the following example:

```
'view' => [
    'theme' => 'app\themes\MyTheme',
    'renderers' => [
        // you may add Smarty or Twig renderer here
    ]
    // ...
]
```

For more details and usage information on View, see the [guide article on views](/docs/guide/structure-views/index.md).

## Properties

| Property | Type | Description | Defined by |
| --- | --- | --- | --- |
| [`$assetBundles`](#property-assetBundles) | `array<string,` [`AssetBundle`](/docs/api/yii/web/assetbundle/index.md)`\|bool>` | List of the registered asset bundles. Default: `[]`. | `View` |
| [`$assetManager`](#property-assetManager) | [`AssetManager`](/docs/api/yii/web/assetmanager/index.md) | The asset manager. | `View` |
| <span id="property-behaviors"></span>[`$behaviors`](/docs/api/yii/base/component/index.md#property-behaviors) read-only | `array<`[`yii\base\Behavior`](/docs/api/yii/base/behavior/index.md)`<static>>` | List of behaviors attached to this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="property-blocks"></span>[`$blocks`](/docs/api/yii/base/view/index.md#property-blocks) | `array` | A list of named output blocks. Default: `null`. | [`yii\base\View`](/docs/api/yii/base/view/index.md) |
| <span id="property-context"></span>[`$context`](/docs/api/yii/base/view/index.md#property-context) | [`yii\base\ViewContextInterface`](/docs/api/yii/base/viewcontextinterface/index.md) | The context under which the [`renderFile()`](/docs/api/yii/base/view/index.md#method-renderFile) method is being invoked. Default: `null`. | [`yii\base\View`](/docs/api/yii/base/view/index.md) |
| <span id="property-css"></span>`$css` | `array` | The registered CSS code blocks. Default: `[]`. | `View` |
| <span id="property-cssFiles"></span>`$cssFiles` | `array` | The registered CSS files. Default: `[]`. | `View` |
| <span id="property-defaultExtension"></span>[`$defaultExtension`](/docs/api/yii/base/view/index.md#property-defaultExtension) | `string` | The default view file extension. Default: `'php'`. | [`yii\base\View`](/docs/api/yii/base/view/index.md) |
| <span id="property-dynamicContents"></span>[`$dynamicContents`](/docs/api/yii/base/view/index.md#property-dynamicContents) read-only | [`yii\base\DynamicContentAwareInterface`](/docs/api/yii/base/dynamiccontentawareinterface/index.md)`[]` | Class instances supporting dynamic contents. | [`yii\base\View`](/docs/api/yii/base/view/index.md) |
| <span id="property-dynamicPlaceholders"></span>[`$dynamicPlaceholders`](/docs/api/yii/base/view/index.md#property-dynamicPlaceholders) | `array` | A list of placeholders. | [`yii\base\View`](/docs/api/yii/base/view/index.md) |
| <span id="property-js"></span>`$js` | `array` | The registered JS code blocks Default: `[]`. | `View` |
| <span id="property-jsFiles"></span>`$jsFiles` | `array` | The registered JS files. Default: `[]`. | `View` |
| <span id="property-linkTags"></span>`$linkTags` | `array` | The registered link tags. Default: `[]`. | `View` |
| <span id="property-metaTags"></span>`$metaTags` | `array` | The registered meta tags. Default: `[]`. | `View` |
| <span id="property-params"></span>[`$params`](/docs/api/yii/base/view/index.md#property-params) | `array` | Custom parameters that are shared among view templates. Default: `[]`. | [`yii\base\View`](/docs/api/yii/base/view/index.md) |
| <span id="property-renderers"></span>[`$renderers`](/docs/api/yii/base/view/index.md#property-renderers) | `array\|null` | A list of available renderers indexed by their corresponding supported file extensions. Default: `null`. | [`yii\base\View`](/docs/api/yii/base/view/index.md) |
| <span id="property-scriptOptions"></span>`$scriptOptions` | `array` | The script tag options. Default: `[]`. Available since 2.0.50. | `View` |
| <span id="property-styleOptions"></span>`$styleOptions` | `array` | The style tag options. Default: `[]`. Available since 2.0.53. | `View` |
| <span id="property-theme"></span>[`$theme`](/docs/api/yii/base/view/index.md#property-theme) | [`yii\base\Theme`](/docs/api/yii/base/theme/index.md)`\|array\|string\|null` | The theme object or the configuration for creating the theme object. Default: `null`. | [`yii\base\View`](/docs/api/yii/base/view/index.md) |
| <span id="property-title"></span>`$title` | `string` | The page title Default: `null`. | `View` |
| <span id="property-viewFile"></span>[`$viewFile`](/docs/api/yii/base/view/index.md#property-viewFile) read-only | `string\|bool` | The view file currently being rendered. | [`yii\base\View`](/docs/api/yii/base/view/index.md) |
| <span id="property-isPageEnded"></span>`$isPageEnded` protected | `bool` | Whether [`endPage()`](/docs/api/yii/web/view/index.md#method-endPage) has been called and all files have been registered Default: `false`. Available since 2.0.44. | `View` |

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| <span id="method-__construct"></span>[`__construct()`](/docs/api/yii/base/baseobject/index.md#method-__construct) | Constructor. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-__call"></span>[`__call()`](/docs/api/yii/base/component/index.md#method-__call) | Calls the named method which is not a class method. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-__clone"></span>[`__clone()`](/docs/api/yii/base/component/index.md#method-__clone) | This method is called after the object is created by cloning an existing one. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-__get"></span>[`__get()`](/docs/api/yii/base/component/index.md#method-__get) | Returns the value of a component property. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-__isset"></span>[`__isset()`](/docs/api/yii/base/component/index.md#method-__isset) | Checks if a property is set, i.e. defined and not null. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-__set"></span>[`__set()`](/docs/api/yii/base/component/index.md#method-__set) | Sets the value of a component property. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-__unset"></span>[`__unset()`](/docs/api/yii/base/component/index.md#method-__unset) | Sets a component property to be null. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-addDynamicPlaceholder"></span>[`addDynamicPlaceholder()`](/docs/api/yii/base/view/index.md#method-addDynamicPlaceholder) | Adds a placeholder for dynamic content. | [`yii\base\View`](/docs/api/yii/base/view/index.md) |
| <span id="method-afterRender"></span>[`afterRender()`](/docs/api/yii/base/view/index.md#method-afterRender) | This method is invoked right after [`renderFile()`](/docs/api/yii/base/view/index.md#method-renderFile) renders a view file. | [`yii\base\View`](/docs/api/yii/base/view/index.md) |
| <span id="method-attachBehavior"></span>[`attachBehavior()`](/docs/api/yii/base/component/index.md#method-attachBehavior) | Attaches a behavior to this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-attachBehaviors"></span>[`attachBehaviors()`](/docs/api/yii/base/component/index.md#method-attachBehaviors) | Attaches a list of behaviors to the component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-beforeRender"></span>[`beforeRender()`](/docs/api/yii/base/view/index.md#method-beforeRender) | This method is invoked right before [`renderFile()`](/docs/api/yii/base/view/index.md#method-renderFile) renders a view file. | [`yii\base\View`](/docs/api/yii/base/view/index.md) |
| <span id="method-beginBlock"></span>[`beginBlock()`](/docs/api/yii/base/view/index.md#method-beginBlock) | Begins recording a block. | [`yii\base\View`](/docs/api/yii/base/view/index.md) |
| [`beginBody()`](#method-beginBody) | Marks the beginning of an HTML body section. | `View` |
| <span id="method-beginCache"></span>[`beginCache()`](/docs/api/yii/base/view/index.md#method-beginCache) | Begins fragment caching. | [`yii\base\View`](/docs/api/yii/base/view/index.md) |
| <span id="method-beginContent"></span>[`beginContent()`](/docs/api/yii/base/view/index.md#method-beginContent) | Begins the rendering of content that is to be decorated by the specified view. | [`yii\base\View`](/docs/api/yii/base/view/index.md) |
| <span id="method-beginPage"></span>[`beginPage()`](/docs/api/yii/base/view/index.md#method-beginPage) | Marks the beginning of a page. | [`yii\base\View`](/docs/api/yii/base/view/index.md) |
| <span id="method-behaviors"></span>[`behaviors()`](/docs/api/yii/base/component/index.md#method-behaviors) | Returns a list of behaviors that this component should behave as. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-canGetProperty"></span>[`canGetProperty()`](/docs/api/yii/base/component/index.md#method-canGetProperty) | Returns a value indicating whether a property can be read. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-canSetProperty"></span>[`canSetProperty()`](/docs/api/yii/base/component/index.md#method-canSetProperty) | Returns a value indicating whether a property can be set. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-className"></span>[`className()`](/docs/api/yii/base/baseobject/index.md#method-className) static | Returns the fully qualified name of this class. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| [`clear()`](#method-clear) | Clears up the registered meta tags, link tags, css/js scripts and files. | `View` |
| <span id="method-detachBehavior"></span>[`detachBehavior()`](/docs/api/yii/base/component/index.md#method-detachBehavior) | Detaches a behavior from the component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-detachBehaviors"></span>[`detachBehaviors()`](/docs/api/yii/base/component/index.md#method-detachBehaviors) | Detaches all behaviors from the component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-endBlock"></span>[`endBlock()`](/docs/api/yii/base/view/index.md#method-endBlock) | Ends recording a block. | [`yii\base\View`](/docs/api/yii/base/view/index.md) |
| [`endBody()`](#method-endBody) | Marks the ending of an HTML body section. | `View` |
| <span id="method-endCache"></span>[`endCache()`](/docs/api/yii/base/view/index.md#method-endCache) | Ends fragment caching. | [`yii\base\View`](/docs/api/yii/base/view/index.md) |
| <span id="method-endContent"></span>[`endContent()`](/docs/api/yii/base/view/index.md#method-endContent) | Ends the rendering of content. | [`yii\base\View`](/docs/api/yii/base/view/index.md) |
| [`endPage()`](#method-endPage) | Marks the ending of an HTML page. | `View` |
| <span id="method-ensureBehaviors"></span>[`ensureBehaviors()`](/docs/api/yii/base/component/index.md#method-ensureBehaviors) | Makes sure that the behaviors declared in [`behaviors()`](/docs/api/yii/base/component/index.md#method-behaviors) are attached to this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-evaluateDynamicContent"></span>[`evaluateDynamicContent()`](/docs/api/yii/base/view/index.md#method-evaluateDynamicContent) | Evaluates the given PHP statements. | [`yii\base\View`](/docs/api/yii/base/view/index.md) |
| [`getAssetManager()`](#method-getAssetManager) | Registers the asset manager being used by this view object. | `View` |
| <span id="method-getBehavior"></span>[`getBehavior()`](/docs/api/yii/base/component/index.md#method-getBehavior) | Returns the named behavior object. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-getBehaviors"></span>[`getBehaviors()`](/docs/api/yii/base/component/index.md#method-getBehaviors) | Returns all behaviors attached to this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-getDynamicContents"></span>[`getDynamicContents()`](/docs/api/yii/base/view/index.md#method-getDynamicContents) | Returns a list of currently active dynamic content class instances. | [`yii\base\View`](/docs/api/yii/base/view/index.md) |
| <span id="method-getDynamicPlaceholders"></span>[`getDynamicPlaceholders()`](/docs/api/yii/base/view/index.md#method-getDynamicPlaceholders) | Returns a list of placeholders for dynamic content. This method is used internally to implement the content caching feature. | [`yii\base\View`](/docs/api/yii/base/view/index.md) |
| <span id="method-getViewFile"></span>[`getViewFile()`](/docs/api/yii/base/view/index.md#method-getViewFile) |  | [`yii\base\View`](/docs/api/yii/base/view/index.md) |
| <span id="method-hasEventHandlers"></span>[`hasEventHandlers()`](/docs/api/yii/base/component/index.md#method-hasEventHandlers) | Returns a value indicating whether there is any handler attached to the named event. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-hasMethod"></span>[`hasMethod()`](/docs/api/yii/base/component/index.md#method-hasMethod) | Returns a value indicating whether a method is defined. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-hasProperty"></span>[`hasProperty()`](/docs/api/yii/base/component/index.md#method-hasProperty) | Returns a value indicating whether a property is defined for this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| [`head()`](#method-head) | Marks the position of an HTML head section. | `View` |
| <span id="method-init"></span>[`init()`](/docs/api/yii/base/view/index.md#method-init) | Initializes the view component. | [`yii\base\View`](/docs/api/yii/base/view/index.md) |
| <span id="method-off"></span>[`off()`](/docs/api/yii/base/component/index.md#method-off) | Detaches an existing event handler from this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-on"></span>[`on()`](/docs/api/yii/base/component/index.md#method-on) | Attaches an event handler to an event. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-popDynamicContent"></span>[`popDynamicContent()`](/docs/api/yii/base/view/index.md#method-popDynamicContent) | Removes a last class instance supporting dynamic contents from a list of currently active dynamic content class instances. | [`yii\base\View`](/docs/api/yii/base/view/index.md) |
| <span id="method-pushDynamicContent"></span>[`pushDynamicContent()`](/docs/api/yii/base/view/index.md#method-pushDynamicContent) | Adds a class instance supporting dynamic contents to the end of a list of currently active dynamic content class instances. | [`yii\base\View`](/docs/api/yii/base/view/index.md) |
| [`registerAssetBundle()`](#method-registerAssetBundle) | Registers the named asset bundle. | `View` |
| [`registerCsrfMetaTags()`](#method-registerCsrfMetaTags) | Registers CSRF meta tags. | `View` |
| [`registerCss()`](#method-registerCss) | Registers a CSS code block. | `View` |
| [`registerCssFile()`](#method-registerCssFile) | Registers a CSS file. | `View` |
| [`registerJs()`](#method-registerJs) | Registers a JS code block. | `View` |
| [`registerJsFile()`](#method-registerJsFile) | Registers a JS file. | `View` |
| [`registerJsVar()`](#method-registerJsVar) | Registers a JS code block defining a variable. The name of variable will be used as key, preventing duplicated variable names. | `View` |
| [`registerLinkTag()`](#method-registerLinkTag) | Registers a link tag. | `View` |
| [`registerMetaTag()`](#method-registerMetaTag) | Registers a meta tag. | `View` |
| <span id="method-render"></span>[`render()`](/docs/api/yii/base/view/index.md#method-render) | Renders a view. | [`yii\base\View`](/docs/api/yii/base/view/index.md) |
| [`renderAjax()`](#method-renderAjax) | Renders a view in response to an AJAX request. | `View` |
| <span id="method-renderDynamic"></span>[`renderDynamic()`](/docs/api/yii/base/view/index.md#method-renderDynamic) | Renders dynamic content returned by the given PHP statements. | [`yii\base\View`](/docs/api/yii/base/view/index.md) |
| <span id="method-renderFile"></span>[`renderFile()`](/docs/api/yii/base/view/index.md#method-renderFile) | Renders a view file. | [`yii\base\View`](/docs/api/yii/base/view/index.md) |
| <span id="method-renderPhpFile"></span>[`renderPhpFile()`](/docs/api/yii/base/view/index.md#method-renderPhpFile) | Renders a view file as a PHP script. | [`yii\base\View`](/docs/api/yii/base/view/index.md) |
| [`setAssetManager()`](#method-setAssetManager) | Sets the asset manager. | `View` |
| <span id="method-setDynamicPlaceholders"></span>[`setDynamicPlaceholders()`](/docs/api/yii/base/view/index.md#method-setDynamicPlaceholders) | Sets a list of placeholders for dynamic content. This method is used internally to implement the content caching feature. | [`yii\base\View`](/docs/api/yii/base/view/index.md) |
| <span id="method-trigger"></span>[`trigger()`](/docs/api/yii/base/component/index.md#method-trigger) | Triggers an event. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-findViewFile"></span>[`findViewFile()`](/docs/api/yii/base/view/index.md#method-findViewFile) protected | Finds the view file based on the given view name. | [`yii\base\View`](/docs/api/yii/base/view/index.md) |
| <span id="method-getRequestedViewFile"></span>[`getRequestedViewFile()`](/docs/api/yii/base/view/index.md#method-getRequestedViewFile) protected |  | [`yii\base\View`](/docs/api/yii/base/view/index.md) |
| [`registerAssetFiles()`](#method-registerAssetFiles) protected | Registers all files provided by an asset bundle including depending bundles files. | `View` |
| [`renderBodyBeginHtml()`](#method-renderBodyBeginHtml) protected | Renders the content to be inserted at the beginning of the body section. | `View` |
| [`renderBodyEndHtml()`](#method-renderBodyEndHtml) protected | Renders the content to be inserted at the end of the body section. | `View` |
| [`renderHeadHtml()`](#method-renderHeadHtml) protected | Renders the content to be inserted in the head section. | `View` |
| [`wrapLoadScript()`](#method-wrapLoadScript) protected | Wraps script content for POS_LOAD position. | `View` |
| [`wrapReadyScript()`](#method-wrapReadyScript) protected | Wraps script content for POS_READY position. | `View` |

## Events

| Event | Type | Description | Defined by |
| --- | --- | --- | --- |
| <span id="event-EVENT_BEGIN_BODY"></span>`EVENT_BEGIN_BODY` | `yii\web\Event` | An event that is triggered by [`beginBody()`](/docs/api/yii/web/view/index.md#method-beginBody). Event name: `'beginBody'`. | `View` |
| <span id="event-EVENT_END_BODY"></span>`EVENT_END_BODY` | `yii\web\Event` | An event that is triggered by [`endBody()`](/docs/api/yii/web/view/index.md#method-endBody). Event name: `'endBody'`. | `View` |
| <span id="event-EVENT_BEGIN_PAGE"></span>[`EVENT_BEGIN_PAGE`](/docs/api/yii/base/view/index.md#event-EVENT_BEGIN_PAGE) | [`yii\base\Event`](/docs/api/yii/base/event/index.md) | An event that is triggered by [`beginPage()`](/docs/api/yii/base/view/index.md#method-beginPage). Event name: `'beginPage'`. | [`yii\base\View`](/docs/api/yii/base/view/index.md) |
| <span id="event-EVENT_END_PAGE"></span>[`EVENT_END_PAGE`](/docs/api/yii/base/view/index.md#event-EVENT_END_PAGE) | [`yii\base\Event`](/docs/api/yii/base/event/index.md) | An event that is triggered by [`endPage()`](/docs/api/yii/base/view/index.md#method-endPage). Event name: `'endPage'`. | [`yii\base\View`](/docs/api/yii/base/view/index.md) |
| <span id="event-EVENT_BEFORE_RENDER"></span>[`EVENT_BEFORE_RENDER`](/docs/api/yii/base/view/index.md#event-EVENT_BEFORE_RENDER) | [`yii\base\ViewEvent`](/docs/api/yii/base/viewevent/index.md) | An event that is triggered by [`renderFile()`](/docs/api/yii/base/view/index.md#method-renderFile) right before it renders a view file. Event name: `'beforeRender'`. | [`yii\base\View`](/docs/api/yii/base/view/index.md) |
| <span id="event-EVENT_AFTER_RENDER"></span>[`EVENT_AFTER_RENDER`](/docs/api/yii/base/view/index.md#event-EVENT_AFTER_RENDER) | [`yii\base\ViewEvent`](/docs/api/yii/base/viewevent/index.md) | An event that is triggered by [`renderFile()`](/docs/api/yii/base/view/index.md#method-renderFile) right after it renders a view file. Event name: `'afterRender'`. | [`yii\base\View`](/docs/api/yii/base/view/index.md) |

## Constants

| Constant | Value | Description | Defined by |
| --- | --- | --- | --- |
| <span id="const-POS_HEAD"></span>`POS_HEAD` | `1` | The location of registered JavaScript code block or files. | `View` |
| <span id="const-POS_BEGIN"></span>`POS_BEGIN` | `2` | The location of registered JavaScript code block or files. | `View` |
| <span id="const-POS_END"></span>`POS_END` | `3` | The location of registered JavaScript code block or files. | `View` |
| <span id="const-POS_READY"></span>`POS_READY` | `4` | The location of registered JavaScript code block. | `View` |
| <span id="const-POS_LOAD"></span>`POS_LOAD` | `5` | The location of registered JavaScript code block. | `View` |
| <span id="const-PH_HEAD"></span>`PH_HEAD` | `'<![CDATA[YII-BLOCK-HEAD]]>'` | This is internally used as the placeholder for receiving the content registered for the head section. | `View` |
| <span id="const-PH_BODY_BEGIN"></span>`PH_BODY_BEGIN` | `'<![CDATA[YII-BLOCK-BODY-BEGIN]]>'` | This is internally used as the placeholder for receiving the content registered for the beginning of the body section. | `View` |
| <span id="const-PH_BODY_END"></span>`PH_BODY_END` | `'<![CDATA[YII-BLOCK-BODY-END]]>'` | This is internally used as the placeholder for receiving the content registered for the end of the body section. | `View` |

## Property details

### $assetBundles <span id="property-assetBundles"></span>

```php
public array<string, yii\web\AssetBundle|bool> $assetBundles = []
```

List of the registered asset bundles.

The keys are the
bundle names, and the values are the registered [`AssetBundle`](/docs/api/yii/web/assetbundle/index.md) objects.

### $assetManager <span id="property-assetManager"></span>

```php
public yii\web\AssetManager $assetManager
```

The asset manager.

Defaults to the "assetManager" application
component.

## Method details

### beginBody() <span id="method-beginBody"></span>

```php
public function beginBody(): mixed
```

Marks the beginning of an HTML body section.

**Returns**

`mixed`

### clear() <span id="method-clear"></span>

```php
public function clear(): mixed
```

Clears up the registered meta tags, link tags, css/js scripts and files.

**Returns**

`mixed`

### endBody() <span id="method-endBody"></span>

```php
public function endBody(): mixed
```

Marks the ending of an HTML body section.

**Returns**

`mixed`

### endPage() <span id="method-endPage"></span>

```php
public function endPage(bool $ajaxMode = false): mixed
```

Marks the ending of an HTML page.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$ajaxMode` | `bool` | Whether the view is rendering in AJAX mode. If true, the JS scripts registered at [`POS_READY`](/docs/api/yii/web/view/index.md#const-POS_READY) and [`POS_LOAD`](/docs/api/yii/web/view/index.md#const-POS_LOAD) positions will be rendered at the end of the view like normal scripts. |

**Returns**

`mixed`

### getAssetManager() <span id="method-getAssetManager"></span>

```php
public function getAssetManager(): yii\web\AssetManager
```

Registers the asset manager being used by this view object.

**Returns**

[`AssetManager`](/docs/api/yii/web/assetmanager/index.md): The asset manager. Defaults to the "assetManager" application component.

### head() <span id="method-head"></span>

```php
public function head(): mixed
```

Marks the position of an HTML head section.

**Returns**

`mixed`

### registerAssetBundle() <span id="method-registerAssetBundle"></span>

```php
public function registerAssetBundle(string $name, int|null $position = null): yii\web\AssetBundle
```

Registers the named asset bundle.

All dependent asset bundles will be registered.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `string` | The class name of the asset bundle (without the leading backslash) |
| `$position` | `int\|null` | If set, this forces a minimum position for javascript files. This will adjust depending assets javascript file position or fail if requirement can not be met. If this is null, asset bundles position settings will not be changed. See [`registerJsFile()`](/docs/api/yii/web/view/index.md#method-registerJsFile) for more details on javascript position. |

**Returns**

[`AssetBundle`](/docs/api/yii/web/assetbundle/index.md): The registered asset bundle instance

**Throws**

- [`yii\base\InvalidConfigException`](/docs/api/yii/base/invalidconfigexception/index.md): if the asset bundle does not exist or a circular dependency is detected

### registerCsrfMetaTags() <span id="method-registerCsrfMetaTags"></span>

```php
public function registerCsrfMetaTags(): mixed
```

Registers CSRF meta tags.

They are rendered dynamically to retrieve a new CSRF token for each request.

```
$view->registerCsrfMetaTags();
```

The above code will result in `<meta name="csrf-param" content="[yii\web\Request::$csrfParam]">`
and `<meta name="csrf-token" content="tTNpWKpdy-bx8ZmIq9R72...K1y8IP3XGkzZA==">` added to the page.

Note: Hidden CSRF input of ActiveForm will be automatically refreshed by calling `window.yii.refreshCsrfToken()`
from `yii.js`.

**Returns**

`mixed`

**Since**

2.0.13

### registerCss() <span id="method-registerCss"></span>

```php
public function registerCss(string $css, array $options = [], string|null $key = null): mixed
```

Registers a CSS code block.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$css` | `string` | The content of the CSS code block to be registered |
| `$options` | `array` | The HTML attributes for the `<style>`-tag. |
| `$key` | `string\|null` | The key that identifies the CSS code block. If null, it will use $css as the key. If two CSS code blocks are registered with the same key, the latter will overwrite the former. |

**Returns**

`mixed`

### registerCssFile() <span id="method-registerCssFile"></span>

```php
public function registerCssFile(string $url, yii\web\RegisterCssFileOptions $options = [], string|null $key = null): mixed
```

Registers a CSS file.

This method should be used for simple registration of CSS files. If you want to use features of
[`AssetManager`](/docs/api/yii/web/assetmanager/index.md) like appending timestamps to the URL and file publishing options, use [`AssetBundle`](/docs/api/yii/web/assetbundle/index.md)
and [`registerAssetBundle()`](/docs/api/yii/web/view/index.md#method-registerAssetBundle) instead.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$url` | `string` | The CSS file to be registered. |
| `$options` | `yii\web\RegisterCssFileOptions` | The HTML attributes for the link tag. Please refer to [`Html::cssFile()`](/docs/api/yii/helpers/basehtml/index.md#method-cssFile) for the supported options. The following options are specially handled and are not treated as HTML attributes: - `depends`: array, specifies the names of the asset bundles that this CSS file depends on. - `appendTimestamp`: bool whether to append a timestamp to the URL. |
| `$key` | `string\|null` | The key that identifies the CSS script file. If null, it will use $url as the key. If two CSS files are registered with the same key, the latter will overwrite the former. |

**Returns**

`mixed`

**Throws**

- [`yii\base\InvalidConfigException`](/docs/api/yii/base/invalidconfigexception/index.md)

### registerJs() <span id="method-registerJs"></span>

```php
public function registerJs(string $js, int $position = \self::POS_READY, string|null $key = null): mixed
```

Registers a JS code block.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$js` | `string` | The JS code block to be registered |
| `$position` | `int` | The position at which the JS script tag should be inserted in a page. The possible values are: - [`POS_HEAD`](/docs/api/yii/web/view/index.md#const-POS_HEAD): in the head section - [`POS_BEGIN`](/docs/api/yii/web/view/index.md#const-POS_BEGIN): at the beginning of the body section - [`POS_END`](/docs/api/yii/web/view/index.md#const-POS_END): at the end of the body section - [`POS_LOAD`](/docs/api/yii/web/view/index.md#const-POS_LOAD): enclosed within a `window` load event listener. - [`POS_READY`](/docs/api/yii/web/view/index.md#const-POS_READY): enclosed within a `DOMContentLoaded` event listener. This is the default value. |
| `$key` | `string\|null` | The key that identifies the JS code block. If `null`, it will use $js as the key. If two JS code blocks are registered with the same key, the latter will overwrite the former. |

**Returns**

`mixed`

### registerJsFile() <span id="method-registerJsFile"></span>

```php
public function registerJsFile(string $url, yii\web\RegisterJsFileOptions $options = [], string|null $key = null): mixed
```

Registers a JS file.

This method should be used for simple registration of JS files. If you want to use features of
[`AssetManager`](/docs/api/yii/web/assetmanager/index.md) like appending timestamps to the URL and file publishing options, use [`AssetBundle`](/docs/api/yii/web/assetbundle/index.md)
and [`registerAssetBundle()`](/docs/api/yii/web/view/index.md#method-registerAssetBundle) instead.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$url` | `string` | The JS file to be registered. |
| `$options` | `yii\web\RegisterJsFileOptions` | The HTML attributes for the script tag. The following options are specially handled and are not treated as HTML attributes: - `depends`: array, specifies the names of the asset bundles that this JS file depends on. - `position`: specifies where the JS script tag should be inserted in a page. The possible values are: * [`POS_HEAD`](/docs/api/yii/web/view/index.md#const-POS_HEAD): in the head section * [`POS_BEGIN`](/docs/api/yii/web/view/index.md#const-POS_BEGIN): at the beginning of the body section * [`POS_END`](/docs/api/yii/web/view/index.md#const-POS_END): at the end of the body section. This is the default value. - `appendTimestamp`: bool whether to append a timestamp to the URL. Please refer to [`Html::jsFile()`](/docs/api/yii/helpers/basehtml/index.md#method-jsFile) for other supported options. |
| `$key` | `string\|null` | The key that identifies the JS script file. If null, it will use $url as the key. If two JS files are registered with the same key at the same position, the latter will overwrite the former. Note that position option takes precedence, thus files registered with the same key, but different position option will not override each other. |

**Returns**

`mixed`

**Throws**

- [`yii\base\InvalidConfigException`](/docs/api/yii/base/invalidconfigexception/index.md)

### registerJsVar() <span id="method-registerJsVar"></span>

```php
public function registerJsVar(string $name, array|string $value, int $position = \self::POS_HEAD): mixed
```

Registers a JS code block defining a variable. The name of variable will be
used as key, preventing duplicated variable names.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `string` | Name of the variable |
| `$value` | `array\|string` | Value of the variable |
| `$position` | `int` | The position in a page at which the JavaScript variable should be inserted. The possible values are: - [`POS_HEAD`](/docs/api/yii/web/view/index.md#const-POS_HEAD): in the head section. This is the default value. - [`POS_BEGIN`](/docs/api/yii/web/view/index.md#const-POS_BEGIN): at the beginning of the body section. - [`POS_END`](/docs/api/yii/web/view/index.md#const-POS_END): at the end of the body section. - [`POS_LOAD`](/docs/api/yii/web/view/index.md#const-POS_LOAD): enclosed within a `window` load event listener. - [`POS_READY`](/docs/api/yii/web/view/index.md#const-POS_READY): enclosed within a `DOMContentLoaded` event listener. |

**Returns**

`mixed`

**Since**

2.0.14

### registerLinkTag() <span id="method-registerLinkTag"></span>

```php
public function registerLinkTag(array $options, string|null $key = null): mixed
```

Registers a link tag.

For example, a link tag for a custom [favicon](https://www.w3.org/2005/10/howto-favicon)
can be added like the following:

```
$view->registerLinkTag(['rel' => 'icon', 'type' => 'image/png', 'href' => '/myicon.png']);
```

which will result in the following HTML: `<link rel="icon" type="image/png" href="/myicon.png">`.

**Note:** To register link tags for CSS stylesheets, use [`registerCssFile()`](/docs/api/yii/web/view/index.md#method-registerCssFile) instead, which
has more options for this kind of link tag.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$options` | `array` | The HTML attributes for the link tag. |
| `$key` | `string\|null` | The key that identifies the link tag. If two link tags are registered with the same key, the latter will overwrite the former. If this is null, the new link tag will be appended to the existing ones. |

**Returns**

`mixed`

### registerMetaTag() <span id="method-registerMetaTag"></span>

```php
public function registerMetaTag(array $options, string|null $key = null): mixed
```

Registers a meta tag.

For example, a description meta tag can be added like the following:

```
$view->registerMetaTag([
    'name' => 'description',
    'content' => 'This website is about funny raccoons.'
]);
```

will result in the meta tag `<meta name="description" content="This website is about funny raccoons.">`.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$options` | `array` | The HTML attributes for the meta tag. |
| `$key` | `string\|null` | The key that identifies the meta tag. If two meta tags are registered with the same key, the latter will overwrite the former. If this is null, the new meta tag will be appended to the existing ones. |

**Returns**

`mixed`

### renderAjax() <span id="method-renderAjax"></span>

```php
public function renderAjax(string $view, array $params = [], object|null $context = null): string
```

Renders a view in response to an AJAX request.

This method is similar to [`render()`](/docs/api/yii/base/view/index.md#method-render) except that it will surround the view being rendered
with the calls of [`beginPage()`](/docs/api/yii/base/view/index.md#method-beginPage), [`head()`](/docs/api/yii/web/view/index.md#method-head), [`beginBody()`](/docs/api/yii/web/view/index.md#method-beginBody), [`endBody()`](/docs/api/yii/web/view/index.md#method-endBody) and [`endPage()`](/docs/api/yii/web/view/index.md#method-endPage).
By doing so, the method is able to inject into the rendering result with JS/CSS scripts and files
that are registered with the view.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$view` | `string` | The view name. Please refer to [`render()`](/docs/api/yii/base/view/index.md#method-render) on how to specify this parameter. |
| `$params` | `array` | The parameters (name-value pairs) that will be extracted and made available in the view file. |
| `$context` | `object\|null` | The context that the view should use for rendering the view. If null, existing [`$context`](/docs/api/yii/base/view/index.md#property-context) will be used. |

**Returns**

`string`: The rendering result

**See also**

- [`render()`](/docs/api/yii/base/view/index.md#method-render)

### setAssetManager() <span id="method-setAssetManager"></span>

```php
public function setAssetManager(yii\web\AssetManager $value): mixed
```

Sets the asset manager.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$value` | [`AssetManager`](/docs/api/yii/web/assetmanager/index.md) | The asset manager |

**Returns**

`mixed`

### registerAssetFiles() <span id="method-registerAssetFiles"></span>

```php
protected function registerAssetFiles(string $name): mixed
```

Registers all files provided by an asset bundle including depending bundles files.

Removes a bundle from [`$assetBundles`](/docs/api/yii/web/view/index.md#property-assetBundles) once files are registered.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `string` | Name of the bundle to register |

**Returns**

`mixed`

### renderBodyBeginHtml() <span id="method-renderBodyBeginHtml"></span>

```php
protected function renderBodyBeginHtml(): string
```

Renders the content to be inserted at the beginning of the body section.

The content is rendered using the registered JS code blocks and files.

**Returns**

`string`: The rendered content

### renderBodyEndHtml() <span id="method-renderBodyEndHtml"></span>

```php
protected function renderBodyEndHtml(bool $ajaxMode): string
```

Renders the content to be inserted at the end of the body section.

The content is rendered using the registered JS code blocks and files.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$ajaxMode` | `bool` | Whether the view is rendering in AJAX mode. If true, the JS scripts registered at [`POS_READY`](/docs/api/yii/web/view/index.md#const-POS_READY) and [`POS_LOAD`](/docs/api/yii/web/view/index.md#const-POS_LOAD) positions will be rendered at the end of the view like normal scripts. |

**Returns**

`string`: The rendered content

### renderHeadHtml() <span id="method-renderHeadHtml"></span>

```php
protected function renderHeadHtml(): string
```

Renders the content to be inserted in the head section.

The content is rendered using the registered meta tags, link tags, CSS/JS code blocks and files.

**Returns**

`string`: The rendered content

### wrapLoadScript() <span id="method-wrapLoadScript"></span>

```php
protected function wrapLoadScript(string $script): string
```

Wraps script content for POS_LOAD position.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$script` | `string` | The script content to wrap |

**Returns**

`string`: The wrapped script

**Since**

22.0

### wrapReadyScript() <span id="method-wrapReadyScript"></span>

```php
protected function wrapReadyScript(string $script): string
```

Wraps script content for POS_READY position.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$script` | `string` | The script content to wrap |

**Returns**

`string`: The wrapped script

**Since**

22.0