Find the first file extension that matches for this view template

@param  string $view_root
@param  string $template_name
@return mixed
484105
private function get_file_extension( $view_root, $template_name ) {
		$paths = to_array( $this->get_path_to_views() );
		// get first element in array
		$path = reset( $paths );

		if ( ! empty( $view_root ) ) {
			$path .= '/' . $view_root;
		}

		$path .= '/' . $template_name;

		$files = glob( $path . '.*' );
		//return pathinfo of first $files element
		return pathinfo( reset( $files ), PATHINFO_EXTENSION );
	}
658536
public function searchAndRenderBlock(BaseView $view, string $blockNameSuffix, array $variables = [])
    {
        $viewCacheKey = $view->vars[self::CACHE_KEY_VAR];
        $viewAndSuffixCacheKey = $viewCacheKey.$blockNameSuffix;

        // In templates, we have to deal with two kinds of block hierarchies:
        //
        //   +---------+          +---------+
        //   | Theme B | -------> | Theme A |
        //   +---------+          +---------+
        //
        //   column_cell -------> column_cell
        //       ^
        //       |
        //   text_cell -----> text_cell
        //
        // The first kind of hierarchy is the theme hierarchy. This allows to
        // override the block "text_cell" from Theme A in the extending
        // Theme B. This kind of inheritance needs to be supported by the
        // template engine and, for example, offers "parent()" or similar
        // functions to fall back from the custom to the parent implementation.
        //
        // The second kind of hierarchy is the column type hierarchy. This allows
        // to implement a custom "text_cell" block (no matter in which theme),
        // or to fallback to the block of the parent type, which would be
        // "column_cell" in this example (again, no matter in which theme).
        // If the designers wants to explicitly fallback to "column_cell" in the
        // custom "text_cell", for example because they only wants to wrap
        // a <div> around the original implementation, they can simply call the
        // widget() function again to render the block for the parent type.
        //
        // The second kind is implemented in the following blocks.
        if (!isset($this->blockNameHierarchyMap[$viewAndSuffixCacheKey])) {
            // INITIAL CALL
            // Calculate the hierarchy of template blocks and start on
            // the bottom level of the hierarchy (= "_<id>_<section>" block)
            $blockNameHierarchy = [];

            foreach ($view->vars['block_prefixes'] as $blockNamePrefix) {
                $blockNameHierarchy[] = $blockNamePrefix.'_'.$blockNameSuffix;
            }

            $hierarchyLevel = count($blockNameHierarchy) - 1;
            $hierarchyInit = true;
        } else {
            // RECURSIVE CALL
            // If a block recursively calls searchAndRenderBlock() again, resume rendering
            // using the parent type in the hierarchy.
            $blockNameHierarchy = $this->blockNameHierarchyMap[$viewAndSuffixCacheKey];
            $hierarchyLevel = $this->hierarchyLevelMap[$viewAndSuffixCacheKey] - 1;

            $hierarchyInit = false;
        }

        // The variables are cached globally for a view (instead of for the
        // current suffix)
        if (!isset($this->variableStack[$viewCacheKey])) {
            $this->variableStack[$viewCacheKey] = [];

            // The default variable scope contains all view variables, merged with
            // the variables passed explicitly to the helper
            $scopeVariables = $view->vars;

            $varInit = true;
        } else {
            // Reuse the current scope and merge it with the explicitly passed variables
            $scopeVariables = end($this->variableStack[$viewCacheKey]);

            $varInit = false;
        }

        // Load the resource where this block can be found
        $resource = $this->engine->getResourceForBlockNameHierarchy($view, $blockNameHierarchy, $hierarchyLevel);

        // Update the current hierarchy level to the one at which the resource was
        // found. For example, if looking for "text_cell", but only a resource
        // is found for its parent "column_cell", then the level is updated here
        // to the parent level.
        $hierarchyLevel = $this->engine->getResourceHierarchyLevel($view, $blockNameHierarchy, $hierarchyLevel);

        // The actually existing block name in $resource
        $blockName = $blockNameHierarchy[$hierarchyLevel];

        // Escape if no resource exists for this block
        if (!$resource) {
            if (count($blockNameHierarchy) !== count(array_unique($blockNameHierarchy))) {
                throw new LogicException(
                    sprintf(
                        'Unable to render the %s because the block names array contains duplicates: "%s".',
                        $blockNameSuffix,
                        implode('", "', array_reverse($blockNameHierarchy))
                    )
                );
            }

            throw new LogicException(
                sprintf(
                    'Unable to render the %s as none of the following blocks exist: "%s".',
                    $blockNameSuffix,
                    implode('", "', array_reverse($blockNameHierarchy))
                )
            );
        }

        // Merge the passed with the existing attributes
        if (isset($variables['attr'], $scopeVariables['attr'])) {
            $variables['attr'] = array_replace($scopeVariables['attr'], $variables['attr']);
        }

        // Merge the passed with the exist *label* attributes
        if (isset($variables['label_attr'], $scopeVariables['label_attr'])) {
            $variables['label_attr'] = array_replace($scopeVariables['label_attr'], $variables['label_attr']);
        }

        // Merge the passed with the exist *header* attributes
        if (isset($variables['header_attr'], $scopeVariables['header_attr'])) {
            $variables['header_attr'] = array_replace($scopeVariables['header_attr'], $variables['header_attr']);
        }

        // Merge the passed with the exist *cell* attributes
        if (isset($variables['cell_attr'], $scopeVariables['cell_attr'])) {
            $variables['cell_attr'] = array_replace($scopeVariables['cell_attr'], $variables['cell_attr']);
        }

        // Do not use array_replace_recursive(), otherwise array variables
        // cannot be overwritten
        $variables = array_replace($scopeVariables, $variables);

        // In order to make recursive calls possible, we need to store the block hierarchy,
        // the current level of the hierarchy and the variables so that this method can
        // resume rendering one level higher of the hierarchy when it is called recursively.
        //
        // We need to store these values in maps (associative arrays) because within a
        // call to widget() another call to widget() can be made, but for a different view
        // object. These nested calls should not override each other.
        $this->blockNameHierarchyMap[$viewAndSuffixCacheKey] = $blockNameHierarchy;
        $this->hierarchyLevelMap[$viewAndSuffixCacheKey] = $hierarchyLevel;

        // We also need to store the variables for the view so that we can render other
        // blocks for the same view using the same variables as in the outer block.
        $this->variableStack[$viewCacheKey][] = $variables;

        // Don't optimize these to a protected method, this method will be called at least
        // 5000 times for a grid with 500 rows and it's headers!
        $vars = [
            'vars' => $variables,
            'name' => $view->name ?? null,
        ];

        if ($view instanceof DatagridView) {
            $vars['columns'] = $view->columns;
            $vars['rows'] = $view->getIterator();
        } elseif ($view instanceof HeaderView) {
            $vars['label'] = $variables['label'] ?? $view->label;
            $vars['datagrid'] = $view->datagrid;
        } elseif ($view instanceof CellView) {
            $vars['datagrid'] = $view->datagrid;
            $vars['column'] = $view->column;
            $vars['use_raw'] = $view->useRaw;
            $vars['value'] = $view->value;
            $vars['source'] = $view->source;
        }

        // Do the rendering
        $html = $this->engine->renderBlock($view, $resource, $blockName, $vars);

        // Clear the stack
        array_pop($this->variableStack[$viewCacheKey]);

        // Clear the caches if they were filled for the first time within
        // this function call
        if ($hierarchyInit) {
            unset($this->blockNameHierarchyMap[$viewAndSuffixCacheKey], $this->hierarchyLevelMap[$viewAndSuffixCacheKey]);
        }

        if ($varInit) {
            unset($this->variableStack[$viewCacheKey]);
        }

        return $html;
    }
205653
public function callFunction($name, Template $template = null, $arguments = [])
    {
        $callable = $this->getFunction($name);

        if (\is_array($callable) &&
            isset($callable[0]) &&
            $callable[0] instanceof ExtensionInterface
        ) {
            $callable[0]->template = $template;
        }

        return $callable(...$arguments);
    }
782807
private static function locate_template( $_view ) {

		if ( is_array( $_view ) ) {
			$_views = array();

			if ( isset( $_view[0] ) && false === strpos( $_view[0], '.php' ) ) {
				$_view_count = count( $_view );

				for ( $_view_x = $_view_count; 0 < $_view_x; $_view_x -- ) {
					$_view_v = array_slice( $_view, 0, $_view_x );

					$_views[] = implode( '-', $_view_v ) . '.php';
				}
			} else {
				$_views = $_view;
			}

			$_view = false;

			foreach ( $_views as $_view_check ) {
				$_view = self::locate_template( $_view_check );

				if ( ! empty( $_view ) ) {
					break;
				}
			}

			return $_view;
		}//end if

		// Keep it safe
		$_view = trim( str_replace( array( '../', '\\' ), array( '', '/' ), (string) $_view ) );

		if ( empty( $_view ) ) {
			return false;
		}

		$_real_view = realpath( $_view );

		if ( empty( $_real_view ) ) {
			$_real_view = $_view;
		}

		$located = false;

		// Is the view's file somewhere within the plugin directory tree?
		// Note: we explicitly whitelist PODS_DIR for the case of symlinks (see issue #2945)
		if ( false !== strpos( $_real_view, realpath( WP_PLUGIN_DIR ) ) || false !== strpos( $_real_view, realpath( WPMU_PLUGIN_DIR ) ) || false !== strpos( $_real_view, PODS_DIR ) ) {
			if ( file_exists( $_view ) ) {
				$located = $_view;
			} else {
				$located = apply_filters( 'pods_view_locate_template', $located, $_view );
			}
		} else {
			// The view's file is outside the plugin directory
			$_real_view = trim( $_real_view, '/' );

			if ( empty( $_real_view ) ) {
				return false;
			}

			// Allow views in the theme or child theme
			if ( file_exists( realpath( get_stylesheet_directory() . '/' . $_real_view ) ) ) {
				$located = realpath( get_stylesheet_directory() . '/' . $_real_view );
			} elseif ( file_exists( realpath( get_template_directory() . '/' . $_real_view ) ) ) {
				$located = realpath( get_template_directory() . '/' . $_real_view );
			}
		}//end if

		return $located;

	}
302820
def __getTemplate(template_file_name):
        
        with open(template_file_name) as template_file:
            template_raw = template_file.read()

        template = parse(template_raw)
        return template
111435
def render_404_template!(template_name)
      VIEW_TEMPLATE_ENGINES.each do |engine, extension|
        @preferred_extension = extension.to_s
        find_template(settings.views, template_name, engine) do |file|
          next unless File.file?(file)
          halt send(extension, template_name.to_sym, layout: false)
        end
      end
    end
968449
@Override
    public String getTemplateURI(String controllerName, String templateName, boolean includeExtension) {
        if (templateName.startsWith(SLASH_STR)) {
            return getAbsoluteTemplateURI(templateName, includeExtension);
        }
        else if(templateName.startsWith(RELATIVE_STRING)) {
            return getRelativeTemplateURIInternal(templateName, includeExtension);
        }

        FastStringWriter buf = new FastStringWriter();
        String pathToTemplate = BLANK;

        int lastSlash = templateName.lastIndexOf(SLASH);
        if (lastSlash > -1) {
            pathToTemplate = templateName.substring(0, lastSlash + 1);
            templateName = templateName.substring(lastSlash + 1);
        }
        if(controllerName != null) {
            buf.append(SLASH)
                    .append(controllerName);
        }
        buf.append(SLASH)
                .append(pathToTemplate)
                .append(UNDERSCORE)
                .append(templateName);

        if(includeExtension) {
            return buf.append(EXTENSION).toString();
        }
        else {
            return buf.toString();
        }
    }
182278
function SmartTemplateParser ( $template_filename )
		{
			// Load Template
			if ($hd = @fopen($template_filename, "r"))
			{
				if (filesize($template_filename))
				{
					$this->template = fread($hd, filesize($template_filename));
				}
				else
				{
					$this->template = "SmartTemplate Parser Error: File size is zero byte: '$template_filename'";
				}
				fclose($hd);
				// Extract the name of the template directory
				$this->template_dir = dirname($template_filename);
			}
			else
			{
				$this->template = "SmartTemplate Parser Error: File not found: '$template_filename'";
			}
		}
171061
static protected String extractTemplateUrl(String viewName){
		int i1 = -1;
		int i2 = -1;
		int i3 = -1;
		int i4 = -1;
		i1 = viewName.indexOf(LEFT_BRACKET);
		if (i1 != -1){
			i2 = viewName.indexOf(LEFT_BRACKET, i1+1);
		}
		i4 = viewName.lastIndexOf(RIGHT_BRACKET);
		if (i4 != -1){
			i3 = viewName.lastIndexOf(RIGHT_BRACKET, i4-1);
		}
		
		if ((i1 == -1 || i4 == -1)		// no starting or ending 
				|| (i2*i3 < 0) 			// not matching
				|| (i2 > i3)){			// not matching
			return viewName;		// no valid template descriptor
		}
		
		//////// the format is guaranteed to be valid after this point
		
		String url = null;
		
		if (i2 != -1){
			url = viewName.substring(i1+1, i2);		// prefix{url{...}}postfix
		}else{
			url = viewName.substring(i1+1, i4);		// prefix{url}postfix
		}

		if (i1 > 0){
			String prefix = viewName.substring(0, i1);
			url = prefix + url;
		}
		if (i4 < viewName.length() - 1){
			String postfix = viewName.substring(i4 + 1);
			url = url + postfix;
		}
		
		return url;
	}
481899
protected static function checkTemplatePresence($raw_name)
    {
        $name = str_replace('.', '/', $raw_name);
        if (file_exists(get_template_directory() . "/app/views/${name}.blade.php")) {
            return true;
        }

        if (file_exists(dirname(__DIR__) . "/views/${name}.blade.php")) {
            return true;
        }

        return false;
    }
1013832
function templateFile( $templateName )
    {
        if ( isset( $this->Templates[$templateName] ) )
        {
            return $this->Templates[$templateName]['filepath'];
        }
        return false;
    }
1333489
protected function getTemplate($template, $name)
    {
        $this->template = $this->file->get($template);

        if ($this->needsScaffolding($template))
        {
            return $this->getScaffoldedTemplate($name);
        }

        // Otherwise, just set the file
        // contents to the file name
        return $name . PHP_EOL;
    }
540249
def find_template_companion(template, extension='', check=True):
    

    if check and not os.path.isfile(template):
        yield ''
        return # May be '<stdin>' (click)

    template = os.path.abspath(template)
    template_dirname = os.path.dirname(template)
    template_basename = os.path.basename(template).split('.')

    current_path = template_dirname
    stop_path = os.path.commonprefix((os.getcwd(), current_path))
    stop_path = os.path.dirname(stop_path)

    token = template_basename[0] + '.'

    while True:

        for file in sorted(os.listdir(current_path)):
            if not file.startswith(token):
                continue
            if not file.endswith(extension):
                continue

            file_parts = file.split('.')
            for i in range(1, len(template_basename)):
                if template_basename[:-i] != file_parts[:-1]:
                    continue
                if current_path == template_dirname:
                    if file_parts == template_basename:
                        continue # Do not accept template itself

                yield os.path.join(current_path, file)

        if current_path == stop_path:
            break

        # cd ..
        current_path = os.path.split(current_path)[0]
512304
public function saveTemplate($template_name, array $template_fields = [ ]) {
        $data = $template_fields;
        $data['template'] = $template_name;
        return $this->apiPost('template', $data);
    }
239056
public static function Get($view_name, $data = null)
    {
        ob_start();
        include static::$ViewRoot . $view_name . '.php';
        $view = ob_get_contents();
        ob_end_clean();
        $result = $view;
        return $result;
    }
346411
private function getTemplateFile($name)
    {
        return Request::get('system.root').$this->config['path'].(isset($this->config['module']) ? $this->config['module'] : '').'/'.$name.$this->config['suffix'];
    }
19093
protected function extensions(string $template): string
	{
		// Replace first occurance of extends tag with an empty string
		// and append the template with a view tag

		if(preg_match('/^{%\s*extends:(.*?)\s*%}/i', $template, $matches) > 0)
		{
			$replacement = '<?php $__view__ = $__viewfactory__->create(' . $matches[1] . '); $__renderer__ = $__view__->getRenderer(); ?>';

			$template = preg_replace('/^{%\s*extends:(.*?)\s*%}/i', $replacement, $template, 1);

			$template .= '<?php echo $__view__->render(); ?>';
		}

		return $template;
	}