Is it possible to check in default.phtml file (app\design\frontend\MyNAMESpace\MY_THEME\Magento_Catalog\templates\product\price\amount\default.phtml) that catalog.product.related (block ) is loaded or not?

I want to add condition in default.phtml file if default.phtml file is called in catalog.product.related | product.info.upsell

I am curious to know if this can be possible in any method.


Please try with below code :


//$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]);

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


hope it is helpful to you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.