Find out the "name" for a referenceBlock in Magento 2

Here's how I find them...

Content > Widgets > Add Widget
Type = CMS Static Block
Design Theme = [Your Theme]

Continue

Layout Updates > Add Layout
Display On = [Pick One]

Right click Inspect on "Please Select" underneath Container.
Expand the <select> element in Dev Tools
All the option value='s are your referenceContainer Names.

:)


There are a couple of ways to do this:

  1. Guess
  2. Review Layout for Base, Blank and Luma Themes
  3. Perform IDE Searches for Class and ID Names
  4. Enable 'Enabled Template Path Hints for Storefront' and 'Add Block Names to Hints'.

You can enable path hints and block hints by logging into the admin interface and going to:

Stores > Configuration > Advanced > Developer > Debug

Unfortunately, there's still no surefire way to find these easily, as far as I know. Though it looks like the guys working on the core are on to it:

https://github.com/magento/magento2/issues/571


You can execute the php-cli code below to get a list of all the ~200 referenceBlock. Make sure the path to your Magento 2 root folder is correct. You can also change the instruction variable to list block, container and referenceContainer.

<?php

//$instruction = "container";
//$instruction = "referenceContainer";
$instruction = "block";
//$instruction = "referenceBlock";

$path = '/var/www/html/magento2/vendor/magento';
$command = 'cd '.$path.' && egrep -r -i --include \*.xml "<'.$instruction.'".*?"name=" *';
exec($command, $output);

$container_max_length = 1;
$pattern = '/(.*?):.*<'.$instruction.'.*name="(.*?)".*/';
foreach ($output as $subject) {
  preg_match($pattern, $subject, $matches);
  $containers[$matches[2]][] = $matches[1];
  if (strlen($matches[2]) > $container_max_length) $container_max_length = strlen($matches[2]);
}

$n=1;
ksort($containers);
foreach ($containers as $k => $v) {
  printf("%6s", "$n. ");
  printf("%-".$container_max_length."s".$v[0]."\n", $k);
  $i=1;
  while (isset($v[$i])) {
    printf("      %-".$container_max_length."s".$v[$i]."\n", "");
    $i++;
  }
  $n++;
}

?>