• Модуль: documentgenerator
  • Путь к файлу: ~/bitrix/modules/documentgenerator/lib/body/html.php
  • Класс: BitrixDocumentGeneratorBodyHtml
  • Вызов: Html::processCommand
protected function processCommand(Node $node)
{
	$nodeAttributes = static::getNodeAttributes($node);
	$command = $nodeAttributes['name'];
	if($command == 'if')
	{
		$variableName = $nodeAttributes['condition'];
		$variableValue = $this->values[$variableName];
		if($variableValue)
		{
			$this->replaceCommand($node, $node->getInnerHTML());
		}
		else
		{
			$this->replaceCommand($node, '');
		}
	}
	elseif($command == 'foreach')
	{
		$variableName = $nodeAttributes['from'];
		$variableValue = $this->values[$variableName];
		$innerVariableName = $nodeAttributes['to'];
		if(is_array($variableValue) || $variableValue instanceof Traversable)
		{
			$resultHtml = '';
			foreach($variableValue as $value)
			{
				$body = new static(['CONTENT' => $node->getInnerHTML()]);
				$document = new Document($body);
				$document->setValues([$innerVariableName => $value]);
				$resultHtml .= $document->render();
			}
			$this->replaceCommand($node, $resultHtml);
		}
		else
		{
			$this->replaceCommand($node, '');
		}
	}
	else
	{
		$this->replaceCommand($node, '');
	}
}