@param string $path
@param null   $template

@return string
@author Maximilian Ruta <mr@xtain.net>
323735
protected function findTwigFile($path, $template = null)
    {
        if ($template == null) {
            $template = $this->template;
        }

        return '::' . Html::TWIG_TEMPLATE_PATH . '/' . $template . '/' . $path;
    }
611968
private function renderContent($params = null, $template = null)
    {
        try {
            $mode = null !== $this->getMode() ? $this->getMode() : $this->_object->getMode();
            $this->templateFile = $template;
            if (null === $this->templateFile && null !== $this->_object) {
                $this->templateFile = $this->getTemplateFile($this->_object, $mode);
                if (false === $this->templateFile) {
                    $this->templateFile = $this->getTemplateFile($this->_object, $this->getMode());
                }

                if (false === $this->templateFile && false === $this->_ignoreIfRenderModeNotAvailable) {
                    $this->templateFile = $this->getTemplateFile($this->_object);
                }
            }

            if (false === $this->isValidTemplateFile($this->templateFile)) {
                throw new RendererException(sprintf(
                        'Unable to find file \'%s\' in path (%s)', $template, implode(', ', $this->_scriptdir)
                ), RendererException::SCRIPTFILE_ERROR);
            }
        } catch (RendererException $e) {
            $render = '';

            // Unknown template, try to render subcontent
            if (null !== $this->_object && is_array($this->_object->getData())) {
                foreach ($this->_object->getData() as $subcontents) {
                    $subcontents = (array) $subcontents;

                    foreach ($subcontents as $sc) {
                        if ($sc instanceof RenderableInterface) {
                            $scRender = $this->render(
                                $sc, $this->getMode(), $params, $template, $this->_ignoreIfRenderModeNotAvailable
                            );

                            if (false === $scRender) {
                                throw $e;
                            }

                            $render .= $scRender;
                        }
                    }
                }
            }

            return $render;
        }

        $application = $this->getApplication();
        // Assign vars and parameters
        if (null !== $this->_object) {
            $draft = $this->_object->getDraft();
            $aClassContentClassname = 'BackBee\ClassContent\AbstractClassContent';
            if ($this->_object instanceof $aClassContentClassname && !$this->_object->isLoaded()) {
                // trying to refresh unloaded content
                $em = $application->getEntityManager();

                $classname = get_class($this->_object);
                $uid = $this->_object->getUid();

                $em->detach($this->_object);
                $object = $em->find($classname, $uid);
                if (null !== $object) {
                    $this->_object = $object;
                    if (null !== $draft) {
                        $this->_object->setDraft($draft);
                    }
                }
            }

            $this->assign($this->_object->getData());
            $this->setParam($this->_object->getAllParams());
        }

        if (null !== $application) {
            $application->debug(sprintf(
                'Rendering content `%s(%s)`.',
                get_class($this->_object),
                $this->_object->getUid()
            ));
        }

        return $this->renderTemplate();
    }
1139984
public function render($template=null, array $params=[]) {
		if($template === null)
			$template = $this->template;
		$params = array_merge($this->params, $params);

		return static::renderFile($template, $params);
	}
1251831
public function defaultTemplate($path)
    {
        $dir = explode(':', $path);

        $controller = preg_split('/(?=[A-Z])/', $dir[0]);
        $controller = array_slice($controller, (count($controller) - 2));
        $controller = implode('', $controller);
        $base = __DIR__ . "/../../Resources/views/";

        if ($dir[1] === '') {
            $dir[0] = $dir[0] . ':';
            $tmp = array_slice($dir, 2);
        } else {
            $tmp = array_slice($dir, 1);

            if (!file_exists($base.$tmp[0])) {
                $tmp[0] = 'Default';
            }
        }

        if (file_exists($base.implode('/', $tmp))) {
            return $dir[0] . ':' . implode(':', $tmp);
        } else {
            $file = explode('.', $tmp[count($tmp) - 1]);

            $file[0] = 'default';
            $tmp[count($tmp) - 1] = implode('.', $file);

            if (file_exists($base . implode('/', $tmp))) {
                return $dir[0] . ':' . implode(':', $tmp);
            }
        }

        return $path;
    }
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'.");
    }
502877
protected function resolveTemplate($template)
    {
        if (!$this->pathCache[$template]) {

            foreach (array_reverse($this->templateDirs) as $dir) {
                $path = $dir . DIRECTORY_SEPARATOR . $template .'.'. $this->getFileExtension();
                if (is_readable($path)) {
                    $this->pathCache[$template] = $path;
                    break;
                }
            }

        }

        return $this->pathCache[$template];
    }
865929
public function findTemplates(string $path, string $pattern = null, string $format = 'twig')
    {
        // Use glob() if possible
        if (false === strpos($path, '/**/') && (\defined('GLOB_BRACE') || false === strpos($path, '{'))) {
            $templates = glob(rtrim($path, '/').'/*.{'.$format.'}', \defined('GLOB_BRACE') ? GLOB_BRACE : 0);

            return null === $pattern ? $templates : preg_grep('$'.$pattern.'$', $templates);
        }

        $pattern = rtrim($path, '/').(null === $pattern ? '' : $pattern).'/*.{'.$format.'}';

        $finder = new Finder();
        $regex = Glob::toRegex($pattern);

        // All files in the given template folder
        $filesIterator = $finder->files()->followLinks()->sortByName()->in(\dirname($pattern));

        // Match the actual regex and filter the files
        $filesIterator = $filesIterator->filter(
            function (\SplFileInfo $info) use ($regex) {
                $path = $info->getPathname();

                return preg_match($regex, $path) && $info->isFile();
            }
        );

        $files = iterator_to_array($filesIterator);

        return array_keys($files);
    }
184914
public function templatePath($path = null)
    {
        deprecationWarning(
            'View::templatePath() is deprecated. ' .
            'Use getTemplatePath()/setTemplatePath() instead.'
        );

        if ($path === null) {
            return $this->templatePath;
        }

        $this->templatePath = $path;
    }
18643
final public function render($template=null, $data=null)
    {
        $renderType = $this->getRenderType();
        switch ($renderType) {
            case 'json':
                $this->renderJson($data);
                break;
            case 'xml':
                $this->renderXml($data);
                break;
            case 'html':
                $this->renderHtml($template, $data);
                break;
            default:
                $string = print_r($data, true);
                $this->renderText($string);
                break;
        }
        
        return $this->response;
    }
625207
protected function templatePath($path, array $path_vars = []) {
    if (strpos($path, '{') !== false) {
      extract($path_vars);
      preg_match_all('@\{\$([A-Za-z0-9_]*)\}@i', $path, $matches);
      if (!empty($matches[1])) {
        foreach ($matches[1] as $var) {
          $path = str_replace('{$' . $var . '}', $$var, $path);
        }
      }
    }

    return $path;
  }
970754
public function compile(Template $template)
    {
        // Otherwise, we look for a compile method
        $method = 'compile'.ucfirst($template->getName());
        if (!method_exists($this, $method)) {
            return null;
        }

        return $this->$method($template);
    }
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;
    }
637886
private function getDomainRegex($template)
    {
        if (preg_match('#https?://(.*)#', $template, $matches)) {
            $template = $matches[1];
        }
        $parameters = [];
        if (strpos($template, '<') !== false) {
            $template = preg_replace_callback(
                '/<(?:\w+):?([^>]+)?>/u',
                function ($matches) use (&$parameters) {
                    $key = '#' . count($parameters) . '#';
                    $parameters[$key] = isset($matches[1]) ? $matches[1] : '\w+';
                    return $key;
                },
                $template
            );
        }
        $template = preg_quote($template);
        $template = strtr($template, $parameters);
        return '/^' . $template . '$/u';
    }
114441
protected function normalizePath($path)
    {
        $path = Alias::getAlias($path, ['lang' => $this->locale]);
        $path = FileHelper::normalizePath($path, DIRECTORY_SEPARATOR, false);

        if (!pathinfo($path, PATHINFO_EXTENSION)) {
            $path .= '.' . $this->defaultExtension;
        }
        $normalizePath = $path;
        // relative path
        if ((strpos($normalizePath, DIRECTORY_SEPARATOR) === false || strpos($normalizePath, '.' . DIRECTORY_SEPARATOR) !== false) && $this->path) {
            $normalizePath = dirname($this->path) . DIRECTORY_SEPARATOR . $normalizePath;
            $normalizePath = realpath($normalizePath);
        }

        if (!file_exists($normalizePath)) {
            throw new TemplateException(TemplateException::UNKNOWN_FILE, ['path' => $path]);
        }

        return $normalizePath;
    }
111972
public function getTemplateDir($key = null)
    {
        if ($key === null) {
            if (count($this->templateDirs) > 0) {
                return $this->templateDirs;
            }
            return null;
        }
        if (is_string($key) === 'string' || is_int($key)) {
            return isset($this->templateDirs[$key]) ? $this->templateDirs[$key] : null;
        }
        return null;
    }
62987
public function getTwigTemplate($content = array(), $template = null, $directory = null)
        {
            if ($template && $directory) {
                $loader = new Twig_Loader_Filesystem($directory);
            } else {
                $loader   = new Twig_Loader_Filesystem(__DIR__ . "/../../views");
                $template = 'email.twig';
            }
            $twig = new Twig_Environment($loader);

            return $twig->render($template, array(
                'email_title' => $this->email_title,
                'body_color'  => $this->body_color,
                'table_color' => $this->table_color,
                'content'     => $content
            ));
        }
558428
protected function _templatePath($path, array $vars = array())
    {
        if (strpos($path, '{') !== false) {
            preg_match_all('#\{\$([_a-z0-9]*)\}#i', $path, $matches);
            if (!empty($matches[1])) {
                foreach ($matches[1] as $var) {
                    $path = str_replace('{$' . $var . '}', isset($vars[$var]) ? $vars[$var] : null, $path);
                }
            }
        }
        return $path;
    }