core-bundle/src/Resources/contao/library/Contao/TemplateInheritance.php
public function block($name)
	{
		$this->arrBlockNames[] = $name;

		// Root template
		if ($this->strParent === null)
		{
			// Register the block name
			if (!isset($this->arrBlocks[$name]))
			{
				$this->arrBlocks[$name] = '[[TL_PARENT]]';
			}

			// Combine the contents of the child blocks
			elseif (\is_array($this->arrBlocks[$name]))
			{
				$callback = function ($current, $parent) {
					return str_replace('[[TL_PARENT]]', $parent, $current);
				};

				$this->arrBlocks[$name] = array_reduce($this->arrBlocks[$name], $callback, '[[TL_PARENT]]');
			}

			// Handle nested blocks
			if ($this->arrBlocks[$name] != '[[TL_PARENT]]')
			{
				// Output everything before the first TL_PARENT tag
				if (strpos($this->arrBlocks[$name], '[[TL_PARENT]]') !== false)
				{
					list($content) = explode('[[TL_PARENT]]', $this->arrBlocks[$name], 2);
					echo $content;
				}

				// Output the current block and start a new output buffer to remove the following blocks
				else
				{
					echo $this->arrBlocks[$name];
					ob_start();
					++$this->intBufferLevel;
				}
			}
		}

		// Child template
		else
		{
			// Clean the output buffer
			ob_clean();

			// Check for nested blocks
			if (\count($this->arrBlockNames) > 1)
			{
				throw new \Exception('Nested blocks are not allowed in child templates');
			}
		}
	}
public function block($name)
	{
		$this->arrBlockNames[] = $name;

		// Root template
		if ($this->strParent === null)
		{
			// Register the block name
			if (!isset($this->arrBlocks[$name]))
			{
				$this->arrBlocks[$name] = '[[TL_PARENT]]';
			}

			// Combine the contents of the child blocks
			elseif (\is_array($this->arrBlocks[$name]))
			{
				$callback = function ($current, $parent) {
					return str_replace('[[TL_PARENT]]', $parent, $current);
				};

				$this->arrBlocks[$name] = array_reduce($this->arrBlocks[$name], $callback, '[[TL_PARENT]]');
			}

			// Handle nested blocks
			if ($this->arrBlocks[$name] != '[[TL_PARENT]]')
			{
				// Output everything before the first TL_PARENT tag
				if (strpos($this->arrBlocks[$name], '[[TL_PARENT]]') !== false)
				{
					list($content) = explode('[[TL_PARENT]]', $this->arrBlocks[$name], 2);
					echo $content;
				}

				// Output the current block and start a new output buffer to remove the following blocks
				else
				{
					echo $this->arrBlocks[$name];
					ob_start();
					++$this->intBufferLevel;
				}
			}
		}

		// Child template
		else
		{
			// Clean the output buffer
			ob_clean();

			// Check for nested blocks
			if (\count($this->arrBlockNames) > 1)
			{
				throw new \Exception('Nested blocks are not allowed in child templates');
			}
		}
	}
Start a new block

@param string $name The block name

@throws \Exception If a child templates contains nested blocks