Contao\Controller::getTemplate PHP Method

getTemplate() public static method

Find a particular template file and return its path
public static getTemplate ( string $strTemplate, string $strFormat = 'html5' ) : string
$strTemplate string The name of the template
$strFormat string The file extension
return string The path to the template file
    public static function getTemplate($strTemplate, $strFormat = 'html5')
    {
        $arrAllowed = \StringUtil::trimsplit(',', strtolower(\Config::get('templateFiles')));
        array_push($arrAllowed, 'html5');
        // see #3398
        if (!in_array($strFormat, $arrAllowed)) {
            throw new \InvalidArgumentException('Invalid output format ' . $strFormat);
        }
        $strTemplate = basename($strTemplate);
        // Check for a theme folder
        if (TL_MODE == 'FE') {
            /** @var PageModel $objPage */
            global $objPage;
            if ($objPage->templateGroup != '') {
                if (\Validator::isInsecurePath($objPage->templateGroup)) {
                    throw new \RuntimeException('Invalid path ' . $objPage->templateGroup);
                }
                return \TemplateLoader::getPath($strTemplate, $strFormat, $objPage->templateGroup);
            }
        }
        return \TemplateLoader::getPath($strTemplate, $strFormat);
    }

Usage Example

 /**
  * Get article for this node.
  *
  * @param $pid
  *
  * @return string
  *
  * @SuppressWarnings(PHPMD.UnusedLocalVariable)
  */
 protected function getArticleNode($pid)
 {
     $listData = new SQLListData($this->getData()->getWidget(), Database::getInstance(), $this->getListDataConfig($pid));
     list($articleLevel, $start) = $listData->browseFrom();
     $level = new \ArrayIterator();
     /** @var SQLListNode $current */
     while ($current = $articleLevel->current()) {
         $node = $current->getData();
         $node['_key'] = 'tl_article::' . $node['_key'];
         $listNode = new SQLListNode($listData, $node);
         $level->append($listNode);
         $articleLevel->next();
     }
     ob_start();
     include Controller::getTemplate('avisota_selectri_with_items');
     return ob_get_clean();
 }