---
title: "Magento 2: Append Block to Specific Container Dynamically"
url: "https://magecomp.com/blog/magento-2-append-block-to-specific-container-dynamically/"
date: "2020-12-28T14:44:12+00:00"
modified: "2025-02-20T09:41:04+00:00"
author:
  name: "Dhiren Vasoya"
  url: "https://magecomp.com/"
categories:
  - "How To"
  - "Magento 2"
word_count: 329
reading_time: "2 min read"
summary: "Hello Magento Friends,"
description: "Magento allows adding and removing blocks as per the requirement. Learn to Append Block to Specific Container Dynamically in Magento 2."
keywords: "How To, Magento 2"
language: "en"
schema_type: "Article"
related_posts:
  - title: "How to Setup Reports Configuration in Magento 2"
    url: "https://magecomp.com/blog/setup-reports-configuration-in-magento-2/"
  - title: "How to Create Custom Artisan Command in Laravel 8?"
    url: "https://magecomp.com/blog/create-custom-artisan-command-laravel-8/"
  - title: "How to add Multi-select Filter in Backend Admin Grid of Magento 2?"
    url: "https://magecomp.com/blog/add-multi-select-filter-backend-admin-grid-magento-2/"
---

# Magento 2: Append Block to Specific Container Dynamically

_Published: December 28, 2020_  
_Author: Dhiren Vasoya_  

![Append Block to Specific Container Dynamically in M2](https://magecomp.com/blog/wp-content/uploads/2020/12/Append-Block-to-Specific-Container-Dynamically-in-M2-1024x512.webp)

**Hello Magento Friends,**

In today’s article, I will be explaining Magento 2: Append Block to Specific Container Dynamically. Let’s check out our previous blog, [**Magento 2: How to use Default Curl Class For API Call**](https://magecomp.com/blog/magento-2-how-to-use-default-curl-class-for-application-program-interface-call/).
[![Magento 2 Speed & Performance Optimization Services](https://magecomp.com/blog/wp-content/uploads/2025/02/Magento-2-Speed-Performance-Optimization-Services-CTA-1.webp)](https://magecomp.com/magento-performance-optimization.html)

## Introduction:
Blocks are used to display information in the form of text, images, videos, or dynamic information in Magento 2. We can add or remove blocks as per the requirement. Sometimes you come across the need to add a block to a specific container dynamically in Magento 2. Let’s dive into the steps to append block to specific container dynamically in Magento 2.
## Steps to Append Block to Specific Container Dynamically in Magento 2:
**Step 1:** First you need to create **events.xml** in the following path
**app\code\Vendor\Extension\etc\frontend**

Now, add the below code
```
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="core_layout_render_element">
    <observer name="load_custom_handler" instance="VendorExtensionObserverAppendblock" />
</event>
```

**Step 2:** Now you need to add the **Appendblock.php** file in the following path
**app\code\Vendor\Extension\Observer**

And finally, add the below code
```
<?php
namespace appcodeVendorExtensionObserver;

use MagentoFrameworkEventObserver;
use MagentoFrameworkEventObserverInterface;

class Appendblock implements ObserverInterface
{
  private static $_layoutSet = false;

  public function execute(Observer $observer)
  {
     // Run this only once
     if(ModifyBlock::$_layoutSet) { return; }
     Appendblock::$_layoutSet = true;
     $layout = $observer->getLayout();
     // Add a new block
     $layout->createBlock('VendorExtensionBlockIndexIndex', 'custom-index-index');
     $layout->setChild('content', 'custom-index-index', 'custom-index-index');
     return;
  }
}
```

That’s it!
[![hyva theme development](https://magecomp.com/blog/wp-content/uploads/2025/02/hyva-theme-development-CTA-5.webp)](https://magecomp.com/services/hyva-theme-development/)

## Conclusion:
Hopefully, everyone is able to append blocks to specific containers dynamically in Magento 2. In case you address the difficulty while performing the above steps, feel free to ask me in the comment section. Spread the article amongst your Magento friends to help them out with the solution. See you back soon, till then stay connected with us.
[![Hire Magento Programmer](https://magecomp.com/blog/wp-content/uploads/2025/02/Hire-Magento-Programmer-CTA-5.webp)](https://magecomp.com/services/hire-magento-programmer/)

**Happy Coding!**


---

_View the original post at: [https://magecomp.com/blog/magento-2-append-block-to-specific-container-dynamically/](https://magecomp.com/blog/magento-2-append-block-to-specific-container-dynamically/)_  
_Served as markdown by [Third Audience](https://github.com/third-audience) v3.5.3_  
_Generated: 2026-08-15 10:15:38 UTC_  
