Load given HTML template in a DOM document

@param  string      $template Original template
@return DOMDocument
431677
protected static function loadAsHTML($template)
	{
		$template = self::replaceCDATA($template);

		$dom  = new DOMDocument;
		$html = '<?xml version="1.0" encoding="utf-8" ?><html><body><div>' . $template . '</div></body></html>';

		$useErrors = libxml_use_internal_errors(true);
		$dom->loadHTML($html, LIBXML_NSCLEAN);
		self::removeInvalidAttributes($dom);
		libxml_use_internal_errors($useErrors);

		// Now dump the thing as XML then reload it with the proper root element
		$xml = '<?xml version="1.0" encoding="utf-8" ?><xsl:template xmlns:xsl="' . self::XMLNS_XSL . '">' . self::innerXML($dom->documentElement->firstChild->firstChild) . '</xsl:template>';

		$useErrors = libxml_use_internal_errors(true);
		$dom->loadXML($xml, LIBXML_NSCLEAN);
		libxml_use_internal_errors($useErrors);

		return $dom;
	}
830559
public function getTemplateFile($template)
    {
        $paths  = $this->config["path"];
        $suffix = $this->config["suffix"];

        foreach ($paths as $path) {
            $file = $path . "/" . $template . $suffix;
            if (is_file($file)) {
                return $file;
            }
        }

        throw new Exception("Could not find template file '$template'.");
    }
977605
public function template($template = null)
    {
        if (is_null($template)) {
            return $this->template;
        } else {
            $this->template = $template;
        }
    }
276422
public function createTemplate(Template &$template)
		{
			$form_data = array(
				'template_name' => $template->getName(),
				'template_subject' => $template->getSubject(),
				'template_body_plain' => $template->getBodyPlain(),
				'template_body_html' => $template->getBodyHtml(),
				'template_body_mobile' => $template->getBodyMobile(),
				'charset' => $template->getCharacterSet(),
				'encoding' => $template->getCharacterEncoding(),
				'folder_id' => $template->getFolderId()
			);
			$data = $this->call('createtemplate', $form_data);

			$template->setTemplateId(trim($data[1]));

			//return $template;
		}
460287
public function load($source)
    {
        $source = mb_convert_encoding($source, 'HTML-ENTITIES', mb_detect_encoding($source));
        $dom = new \DOMDocument();

        // Try to load the source as standard XML document first, then as HTML document
        if (!$dom->loadXML($source, LIBXML_NOWARNING | LIBXML_NOERROR)) {
            $dom = $this->htmlParser->loadHTML($source);
        }

        return $dom;
    }
312047
private function createDOMDocumentFromHTML($html = null) {

        if ($html != null) {
            libxml_use_internal_errors(true);
            $dom = new DOMDocument;
            $dom->loadHTML($html);
            libxml_clear_errors();
            libxml_use_internal_errors(false);
            return $dom;
        }
    }
1171284
protected function getPathToTemplates($template = null)
    {
        $template = Helpers::getPathWithSlash($template ?: Config::getDefaultTemplateName());
        $basePath = base_path(Config::getTemplatesPath() . $template);
        $path = Helpers::getPathWithSlash($basePath);

        if (!$this->isFileExists($path)) {
            throw new Exception('Invalid template. Make sure the following path exists: "' . $path . '"');
        }

        return $path;
    }
388055
public function checkTemplate($template, Tag $tag = null)
	{
		if ($this->disabled)
		{
			return;
		}

		if (!isset($tag))
		{
			$tag = new Tag;
		}

		// Load the template into a DOMDocument
		$dom = TemplateLoader::load($template);

		foreach ($this->collection as $check)
		{
			$check->check($dom->documentElement, $tag);
		}
	}
1228307
public function getTemplateFile($template)
	{
	    if (!is_file($template)) {
	        $template = $this->getTemplatePath() . $this->_getRelativeTemplate($template) . $this->getSuffix();
	    }
	    
	    return $template;
	}
1218880
public function template($template = false, $layout = null)
    {
        if ($template === false) {
            return [
                'template' => $this->_template,
                'layout' => $this->_layout,
            ];
        }
        $this->_template = $template;
        if ($layout !== null) {
            $this->_layout = $layout;
        }

        return $this;
    }
156846
public function setTemplate($template)
    {
        if (is_readable($template) === false) {
            throw new RuntimeException("Unable to read template file “{$template}”.");
        }

        $this->template = $template;

        return $this;
    }
740583
protected function getTemplateData($template) {
		// firstly, check for current locale, if it was set
		if ($this->locale != '') {
			$tdata = $this->getTemplateDataForLocale($template,$this->locale);
			
			// found for this locale. return
			if (is_array($tdata)) {
				return $tdata;
			}
		}
		
		// check for default locale
		// for example, didn't find for locale `ge` but found for default `en`
		if ($this->deflocale != '') {
			$tdata = $this->getTemplateDataForLocale($template,$this->deflocale);
			
			if (is_array($tdata)) {
				return $tdata;
			}
		}
		
		// if nothing found for both locales then check in root templates folder
		// this is normal case for non-internation application where 
		// locales are not used
		$tdata = $this->getTemplateDataForLocale($template,'');
			
		return $tdata;
	}
366319
public function load($template)
    {
        $path['manifest'] = $this->_buildManifestPath($template);

        if (file_exists($path['manifest'])) {

            $this->alias = $template;
            $this->thumbnail = AnRequest::root().'/templates/'.$template.'/thumbnail.png';

            $manifest = json_decode(file_get_contents($path['manifest']));

            foreach ($this->_attributes as $key => $value) {
                if (array_key_exists($key, $manifest)) {
                    $this->$key = $manifest->$key;
                }
            }

            $path['params'] = $this->_buildParamsPath($template);

            if (file_exists($path['params'])) {
                $this->params = parse_ini_file($path['params']);
            }

            return $this;
        }

        return false;
    }
270375
public static function getAdminTemplate($template, $module = null)
    {
        $rtn = null;

        $path = static::getPath($template, $module);

        if (!is_null($path)) {
            $templateSrc = file_get_contents($path . $template . '.html');
            $rtn = new static($templateSrc);
            Event::trigger('AdminTemplateLoaded', $rtn);

            if (!is_null($rtn)) {
                $rtn->addFunction('hash', function ($args) {
                    return md5($args['value']);
                });
            }

            return $rtn;
        }

        throw new \Exception('Template does not exist: ' . $template);
    }
182903
public function useTwigTemplate($template, array $data = array())
	{
		$html = $this->renderer->render($template, $data);
		$this->setHtml($html);
		return $this;
	}
63677
protected function getTemplate($template, $className)
    {
        $this->template = $this->file->get($template);
        $resource = strtolower(Pluralizer::plural(
            str_ireplace('Controller', '', $className)
        ));

        if ($this->needsScaffolding($template))
        {
            $this->template = $this->getScaffoldedController($template, $className);
        }

        $template = str_replace('{{className}}', $className, $this->template);

        return str_replace('{{collection}}', $resource, $template);
    }
746146
protected function compiled($template)
    {
        $template = ltrim($template, '/');
        if (strrchr($template, '.') == $this->extension)
            $template = substr($template, 0, -strlen($this->extension));
        $file = $this->dir . DIRECTORY_SEPARATOR . $template . $this->extension;
        if (!is_file($file))
            throw new \RuntimeException("template not found:$file!");

        $modified = filemtime($file);
        $compiled = $this->temp . DIRECTORY_SEPARATOR . $template . ".{$modified}.php";
        if (!$this->debug && is_file($compiled) && filemtime($compiled) >= $modified)
            return $compiled;

        $content = self::compile(file_get_contents($file), $this->left, $this->right);
        self::writeFile($compiled, $content, $this->temp);

        return $compiled;
    }