Understanding $block->getChildHtml()

As I am learning magento, I had this issue from quite a while. Sometimes I was able to use $block->getChildHtml and sometimes not. So I asked help from my colleague Lee and he helped me to understand the whole concept of $block->getChildHtml();
Supposably I want to display this block in one of my view which block of class ‘Title’

echo $block->getChildHtml('sudeep_block');

So in layout file I have to define this as follows

<!-- page title -->
<block class="Vendor\Product\Block\Html\Title" name="page.main.title"
    <block class="Vendor\Product\Block\Html\Title" name="" as="sudeep_block"


If I don’t put this within <block class=”Vendor\Product\Block\Html\Title”  it will not appear correctly. This is because, we are calling child HTML of this block
Thats the reply from my colleague Lee
“the problem with putting things in the container is that its just a container and things are ordered within that container based on the before and after elements that are added in the xml – it just prints all the blocks out that are set.
I’ve moved it into the title block – this sets it as a child, so you can either call ->getChildHtml() – that will pull all child elements in that block
or ->getChildHtml(‘name-of-block’) – and that will call the specific block that you want
if its available obviously!”

Magento 2 add static block in Layout XML

Here is a quick way on how to add static cms block in the layout

Display CMS Static Block In Phtml File:

Here the code to show CMS Static Block in any template (phtml) file in Magento 2,


Display CMS Static Block In CMS Content:

Here the code to show CMS Static Block in any other CMS static block/page in Magento 2,

{{block class="Magento\\Cms\\Block\\Block" block_id="block_identifier"}}

Display CMS Static Block In XML:
Here the code to show CMS Static Block in any layout (XML) file in Magento 2,


<referenceContainer name="content"> 
<block class="Magento\Cms\Block\Block" name="block_identifier"> 
<argument name="block_id" xsi:type="string">block_identifier</argument> 



Thanks to info at

Magento 2 admin catalog product edit form – categories order

I have recently been doing some developments in Magento 2 and have found out some inconsistency in the product edit form in the admin section.

The desired sort order of the category should be the default position one. However in the product edit admin catalog product edit form, the sort order is not defined therefore, it appears in the way it is returned from the database. This is not very user-friendly especially if you have about 4000 categories to deal with.

Magento 2 admin product edit form category sort order - backend Magento 2 natural - original  category sort order - frontend
admin catalog product edit form – categories order categories order on frontend

Thus to obtain same layout, we have made changed in following pre. You can also create pre pool and add the pre there, but this is a quick fix

My Magento version is community 2.2.6



Go to line 375 and add the following code


Make sure to add this line before

foreach ($collection as $category) {.

So the final code should look like as follows


        foreach ($collection as $category) {
            foreach ([$category->getId(), $category->getParentId()] as $categoryId) {
                if (!isset($categoryById[$categoryId])) {
                    $categoryById[$categoryId] = ['value' => $categoryId];

            $categoryById[$category->getId()]['is_active'] = $category->getIsActive();
            $categoryById[$category->getId()]['label'] = $category->getName();
            $categoryById[$category->getParentId()]['optgroup'][] = &$categoryById[$category->getId()];

            self::CATEGORY_TREE_ID . '_' . $filter,

        return $categoryById[CategoryModel::TREE_ROOT_ID]['optgroup'];

Thus my final version looks as following

Magento 2 quick check list before going live

Hello all

I have been working on Magento2 from quiet a while and getting my hands on its development & deployment. I know it always happens when you develop or customise something and keep on refreshing the page, but you does not get the desired results.

Therefore I have created a quick checklist to make sure all boxes are ticked before you go live. I have also included the commands so that its handy to run them in order

Production mode is enabled

php bin/magento deploy:mode:set production

Cache is first flushed and then enabled

php bin/magento cache:clean
php bin/magento cache:enable

Static contents have been deployed

 php bin/magento setup:static-content:deploy

var folder persmissions

chmod -R 777 var

pub folder persmissions

chmod -R 777 pub

Static contents have been deployed

 php bin/magento setup:static-content:deploy

Catalog has been reindexed

 php bin/magento indexer:reindex

Regular expressions

Some handy regular expressions terms

If you want to remove only specific tags from the html, you can use following regular expression. I use it along with PHP storm.

For example here is my sample code

    <a href="/samplelink/5656/565">
        <i class="fa fa-trash-o fa-2x" aria-hidden="true"></i>
    <a href="/samplelink/21112/21">
        <i class="fa fa-trash-o fa-2x" aria-hidden="true"></i>
    <a href="/samplelink/99/997"> 
        <i class="fa fa-trash-o fa-2x" aria-hidden="true"></i>

if you want to replace all a tags

<a href="/samplelink/99/997">

I will use the following code in regular expressions to find

<a href=".*?"\s*[/>]* 

Calling controller from a View in Yii

There are two ways to call a controller from a view.

$this->forward('/enggdiary/optimiseroutebygoogleapi',true, array('engineer_id'=>$isAdmin));?>






Redirecting all URLs to .com rather than .biz,, .info

I was having this problem with my current site. I have several domains like

Even the problem was Google was indexing all these pages separately and which is not good from the SEO perspective. Therefore, we

This thing is also called as CANONICAL DOMAIN

I used the following code to force all URLs to go to

RewriteBase /
RewriteCond %{HTTP_HOST} !^(www\.)?ukwhitegoods\.co\.uk$ [NC] ////This means was anything other than this pattern is fired, follow the rule

///NC means case sensitive URL
RewriteRule ^(.*)$$1 [R=301,L] ////Its a permanent redirect and LAST RULE

So now all my landing pages goes to

Extending Root Partition in Cent OS from Home directory

For all newbies, it is a common problem when we quickly run out of space (especially if you are a web developer)

Therefore, this tutorial is for users who have much space in home directory but still runs of out space in root

Help from

Make sure all your hd is ext4 formatted and you are logged in as Root

Now install the software

yum install lvm2

Firstly check the directory structure of CentOS


To reduce space from home directory type following:

lvreduce --resizefs --size -700G /dev/centos/home 

To Extend space in root directory type following:

lvextend --resizefs --size +700G /dev/centos/root 

Installing CentOS7 on Raid 1 Proliant microserver Gen8

This blog is for installing the CentOS 7 on HP Proliant Microserver Gen8. It can work on other raid devices too.

The tutorial covers the manual partition as some servers are not able to find the boot devices.

Please proceed to following steps.

First of all Go in the

Step1: Go into Bios enter BIOS (press F9 during boot)
– press CTRL+A (Service Option is hidden by default)
– select “Service Options” -> Processor Power and Utilization Monitoring -> Disable


please see for details

Also setup System Options -> SATA Controller Options -> Embedded SATA Configuration and select RAID configuration


Step2: Go to system Storage configuration by pressing F5 and in it create a RAID 1 logical drive using both the harddisks

Step 3: Now boot system and insert your centos dvd

Step4: Select Language and the version you want to install

Step5: Go in select disk section and select both the disk. At the bottom select manual partition

Step 6: Select New mount point as LVM and click on +

Step 7: Mount point is Boot and desired capacity as 512MB (make sure it is 512 MB on main screen too)

Step 8 Device Type as RAID, File System: ext4, Raid Level is Raid1

Step 9: click on update settings

Step 10: Again click on + from bottom and select new Mount point as ‘/’. Add space how much you want to allot leaving atleast 7GB. I am adding desired capacity as 215GB

Step 11: Now here Device Type is LVM, filesystem as ext4 and now click on Modify for Volume Group

Step 12: Select Raid level in this as RAID1, size policy as Fixed, name as shavg1 and save and then click on update settings

Step 13: Again click on + and now Mount point as SWAP and desired capacity as 6GB

Step 14: Select filesystem as SWAP, device type as LVM and then click on volume group and Modify

Step 15 : Select size policy as Fixed, Raid Level as RAID1 and click save.

Step 16: Check all the values again and click on done

Step 17: There will be summary of changes with top 2 as Destroy format in Red on sdb

Step 18: Accept changes and Click on Begin installation

Step 19: This will take its own time, By the time you can create your root password and create user

Step 20: Reboot the system and it should be good to go.