As shown above, the child layout content should be enclosed within [[yii\base\View::beginContent()|beginContent()]] and
[[yii\base\View::endContent()|endContent()]]. The parameter passed to [[yii\base\View::beginContent()|beginContent()]]
specifies what is the parent layout. It can be either a layout file or alias.
Using the above approach, you can nest layouts in more than one levels.
### Using Blocks <a name="using-blocks"></a>
Blocks allow you to specify the view content in one place while displaying it in another. They are often used together
with layouts. For example, you can define a block in a content view and display it in the layout.
You call [[yii\base\View::beginBlock()|beginBlock()]] and [[yii\base\View::endBlock()|endBlock()]] to define a block.
The block can then be accessed via `$view->blocks[$blockID]`, where `$blockID` stands for a unique ID that you assign
to the block when defining it.
The following example shows how you can use blocks to customize specific parts of a layout in a content view.
First, in a content view, define one or multiple blocks:
```php
...
<?php$this->beginBlock('block1');?>
...content of block1...
<?php$this->endBlock();?>
...
<?php$this->beginBlock('block3');?>
...content of block3...
<?php$this->endBlock();?>
```
Then, in the layout view, render the blocks if they are available, or display some default content if a block is
not defined.
```php
...
<?phpif(isset($this->blocks['block1'])):?>
<?=$this->blocks['block1']?>
<?phpelse:?>
... default content for block1 ...
<?phpendif;?>
...
<?phpif(isset($this->blocks['block2'])):?>
<?=$this->blocks['block2']?>
<?phpelse:?>
... default content for block2 ...
<?phpendif;?>
...
<?phpif(isset($this->blocks['block3'])):?>
<?=$this->blocks['block3']?>
<?phpelse:?>
... default content for block3 ...
<?phpendif;?>
...
```
## Using View Components <a name="using-view-components"></a>
[[yii\base\View|View components]] provides many view-related features. While you can get view components
by creating individual instances of [[yii\base\View]] or its child class, in most cases you will mainly use
the `view` application component. You can configure this component in [application configurations](structure-applications.md#application-configurations)
like the following:
```php
[
// ...
'components'=>[
'view'=>[
'class'=>'app\components\View',
],
// ...
],
]
```
View components provide the following useful view-related features, each described in more details in a separate section:
*[theming](output-theming.md): allows you to develop and change the theme for your Web site.
*[fragment caching](caching-fragment.md): allows you to cache a fragment within a Web page.
*[client script handling](output-client-scripts.md): supports CSS and JavaScript registration and rendering.
*[asset bundle handling](structure-assets.md): supports registering and rendering of [asset bundles](structure-assets.md).
*[alternative template engines](tutorial-template-engines.md): allows you to use other template engines, such as