Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Template.php
Go to the documentation of this file.
1 <?php
7 
11 class Template
12 {
13  const XML_VERSION = '1.0';
14 
15  const XML_ENCODING = 'UTF-8';
16 
20  protected $logger;
21 
25  protected $templateNode;
26 
31  public function __construct(
32  \Psr\Log\LoggerInterface $logger,
33  $content
34  ) {
35  $this->logger = $logger;
36  $document = new \DOMDocument(static::XML_VERSION, static::XML_ENCODING);
37  $document->loadXML($content);
38  $this->templateNode = $document->documentElement;
39  }
40 
46  public function getDocumentElement()
47  {
48  return $this->templateNode;
49  }
50 
57  public function append($content)
58  {
59  $newFragment = $this->templateNode->ownerDocument->createDocumentFragment();
60  $newFragment->appendXML($content);
61  $this->templateNode->appendChild($newFragment);
62  }
63 
69  public function __toString()
70  {
71  try {
72  $this->templateNode->ownerDocument->normalizeDocument();
73  $result = $this->templateNode->ownerDocument->saveHTML();
74  } catch (\Exception $e) {
75  $this->logger->critical($e->getMessage());
76  $result = '';
77  }
78  return $result;
79  }
80 }
__construct(\Psr\Log\LoggerInterface $logger, $content)
Definition: Template.php:31