Determine if a given template exists so that it can be loaded
    if so, or a default alternative can be used if not.
427578
def template_exists(template_name):
    '''
    
    '''
    try:
        template.loader.get_template(template_name)
        return True
    except template.TemplateDoesNotExist:
        return False
1074983
private static boolean isEditableTemplate(@NotNull Template template) {
    Resource resource = template.adaptTo(Resource.class);
    if (resource != null) {
      return resource.getChild(NN_EDITABLE_TEMPLATE_INITIAL) != null
          && resource.getChild(NN_EDITABLE_TEMPLATE_STRUCTURE) != null
          && resource.getChild(NN_EDITABLE_TEMPLATE_POLICIES) != null;
    }
    return false;
  }
438227
def enable_template(name)
      name = name.to_sym

      return false if @enabled_templates.include?(name)

      unless (template_dir = Template.templates[name])
        say "Unknown template #{name}", :red
        exit -1
      end

      new_template = Template::Directory.new(template_dir)

      # mark the template as enabled
      @enabled_templates << name

      # enable any other templates
      new_template.enable.each do |sub_template|
        enable_template(sub_template)
      end

      # append the new template to the end of the list,
      # to override previously loaded templates
      @templates << new_template

      # add the template directory to the source-paths
      self.source_paths << new_template.path
      return true
    end
765035
private DOMNode getExistingTemplate(final String name) {

		try (final Tx tx = app.tx()) {

			return Importer.findSharedComponentByName(name);

		} catch (FrameworkException fex) {
			logger.warn("Unable to determine if template {} already exists, ignoring.", name);
		}

		return null;
	}
553054
def which(template, extension)
      template_with_extension = with_extension(template, extension)

      path = absolute_paths.find do |path|
        File.exists?(File.join(path, template_with_extension))
      end

      if path
        File.join(path, template_with_extension)
      end
    end
684006
def template(tpl, template_adapter=SimpleTemplate, **kwargs):
    '''
    
    '''
    if tpl not in TEMPLATES or DEBUG:
        settings = kwargs.get('template_settings',{})
        lookup = kwargs.get('template_lookup', TEMPLATE_PATH)
        if isinstance(tpl, template_adapter):
            TEMPLATES[tpl] = tpl
            if settings: TEMPLATES[tpl].prepare(settings)
        elif "\n" in tpl or "{" in tpl or "%" in tpl or '$' in tpl:
            TEMPLATES[tpl] = template_adapter(source=tpl, lookup=lookup, settings=settings)
        else:
            TEMPLATES[tpl] = template_adapter(name=tpl, lookup=lookup, settings=settings)
    if not TEMPLATES[tpl]:
        abort(500, 'Template (%s) not found' % tpl)
    kwargs['abort'] = abort
    kwargs['request'] = request
    kwargs['response'] = response
    return TEMPLATES[tpl].render(**kwargs)
308745
public static boolean is(@NotNull Page page, @NotNull TemplatePathInfo @NotNull... templates) {
    if (page == null || templates == null || templates.length == 0) {
      return false;
    }
    String templatePath = page.getProperties().get(NameConstants.PN_TEMPLATE, String.class);
    for (TemplatePathInfo template : templates) {
      if (template.getTemplatePath().equals(templatePath)) {
        return true;
      }
    }
    return false;
  }
558497
public function exists($name)
    {
        if ($name instanceof Template) {
            return true;
        }

        $loader = $this->environment->getLoader();

        if ($loader instanceof ExistsLoaderInterface || method_exists($loader, 'exists')) {
            return $loader->exists((string) $name);
        }

        try {
            // cast possible TemplateReferenceInterface to string because the
            // EngineInterface supports them but LoaderInterface does not
            $loader->getSourceContext((string) $name)->getCode();
        } catch (LoaderError $e) {
            return false;
        }

        return true;
    }
549133
function getTemplate(val, defaultVal) {
  if(isFunction(val)) {
    return val(cloneDeep(defaultVal));
  }
  else if(isArray(val)) {
    return val;
  }
  else {
    return cloneDeep(defaultVal);
  }
}
428591
def CheckTemplates(self, base_dir, version):
    """"""
    major_minor = ".".join(version.split(".")[0:2])
    templates = glob.glob(
        os.path.join(base_dir, "templates/*%s*.zip" % major_minor))
    required_templates = set(
        [x.replace("maj.minor", major_minor) for x in self.REQUIRED_TEMPLATES])

    # Client templates have an extra version digit, e.g. 3.1.0.0
    templates_present = set([
        re.sub(r"_%s[^_]+_" % major_minor, "_%s_" % major_minor,
               os.path.basename(x)) for x in templates
    ])

    difference = required_templates - templates_present
    if difference:
      raise RuntimeError("Missing templates %s" % difference)
633702
def choose_template(self, template):
        '''
        '''
        n1 = int(template)/10
        n2 = int(template)%10
        self.send('^TS'+'0'+str(n1)+str(n2))
1132355
function loadTemplate (file, options) {
    // return cached template if caching enabled
    if (options.cache && GLOBAL.templates[file]) {
        return Promise.resolve(GLOBAL.templates[file])
    }
    // store promise to load template
    var promise = GLOBAL.templates[file] = fsp.readFile(file, 'utf8')
    // compile template file
    .then(data => {
        // replace entry in template cache with template function
        var template = GLOBAL.templates[file] = handlebars.compile(data)
        // resolve with template
        return template
    })
    // return promise
    return promise
}
733510
private final CompiledST loadTemplateResource(String prefix, String unqualifiedFileName) {
        //if (resourceRoot == null) return null;
        //return loadTemplate(resourceRoot, prefix, unqualifiedFileName);
        if (resourceRoots.isEmpty()) return null;
        CompiledST template = null;
        for (URL resourceRoot : resourceRoots) {
            if ((template = loadTemplate(resourceRoot, prefix, unqualifiedFileName)) != null)
                return template;
        }
        return null;
    }
15783
private TemplateClass tryLoadTemplate(String tmplName, RythmEngine engine, TemplateClass callerClass, ICodeType codeType, boolean processTagName) {
        //logger.info(">>> try load %s on [%s] with processTagName: %s", tmplName, callerClass.getKey(), processTagName);
        if (null == engine) {
            engine = getDefaultEngine();
        }
        if (engine.templateRegistered(tmplName)) {
            return null;
        }
        String rythmSuffix = engine.conf().resourceNameSuffix();
        final List<String> suffixes = new ArrayList<String>(Arrays.asList(RythmEngine.VALID_SUFFIXES));
        if (null == codeType) {
            codeType = TemplateResourceBase.getTypeOfPath(engine, tmplName);
        }
        if (ICodeType.DefImpl.RAW == codeType) {
            // use caller's code type
            codeType = callerClass.codeType;
        }
        final String tagNameOrigin = tmplName;
        boolean hasSuffix = false;
        String suffix = "";
        if (processTagName) {
            boolean withRythmSuffix = S.notEmpty(rythmSuffix);
            for (String s : suffixes) {
                if (tmplName.endsWith(s)) {
                    tmplName = tmplName.substring(0, tmplName.lastIndexOf(s));
                    suffix = s;
                    hasSuffix = true;
                    break;
                }
                if (withRythmSuffix && (tmplName.endsWith(s) || tmplName.endsWith(s + rythmSuffix))) {
                    tmplName = tmplName.substring(0, tmplName.lastIndexOf(s));
                    suffix = s + rythmSuffix;
                    hasSuffix = true;
                    break;
                }
            }
        }
        tmplName = tmplName.replace('.', '/');
        String sfx = codeType.resourceNameSuffix();
        if (S.notEmpty(sfx) && !suffixes.get(0).equals(sfx)) {
            suffixes.remove(sfx);
            suffixes.add(0, sfx);
        }

        final List<String> roots = new ArrayList<String>();
        String root0 = this.getResourceLoaderRoot().replace('\\', '/');
        if (root0.endsWith("/")) {
            root0 = root0.substring(0, root0.length() - 1);
        }

        roots.add(root0);

        // call template using relative path
        String currentPath = callerClass.getKey().toString();
        int pos = currentPath.lastIndexOf("/");
        if (-1 != pos) {
            currentPath = currentPath.substring(0, pos);
            if (currentPath.startsWith(root0)) {
                if (currentPath.length() > root0.length()) {
                    roots.add(0, currentPath);
                }
            } else {
                if (currentPath.startsWith("/")) {
                    currentPath = currentPath.substring(1);
                }
                if (!currentPath.startsWith(root0)) currentPath = root0 + "/" + currentPath;
                roots.add(0, currentPath);
            }
        }
        
        // call tag with import path
        if (null != callerClass.importPaths) {
            for (String s: callerClass.importPaths) {
                if (s.startsWith("java")) {
                    continue;
                }
                roots.add(0, root0 + "/" + s.replace('.', '/'));
            }
        }

        String tmplName0 = tmplName;
        for (String root : roots) {
            String tmplName1 = tmplName0;
            if (root.startsWith("/") && !tmplName1.startsWith("/")) {
                tmplName1 = "/" + tmplName0;
            }
            tmplName = tmplName1.startsWith(root) ? tmplName1 : root + "/" + tmplName0;
            if (hasSuffix) {
                ITemplateResource resource = load(tmplName + suffix);
                if (null == resource || !resource.isValid()) {
                    continue;
                }
                TemplateClass tc = engine.resourceManager().resourceLoaded(resource, false);
                return tc;
            } else {
                for (String suffix0 : suffixes) {
                    String path = tmplName + suffix0;
                    ITemplateResource resource = load(path);
                    if (null == resource || !resource.isValid()) {
                        continue;
                    }
                    TemplateClass tc = engine.resourceManager().resourceLoaded(resource, false);
                    return tc;
                }
            }
        }
        TemplateClass tc = processTagName ? tryLoadTemplate(tagNameOrigin, engine, callerClass, codeType, false) : null;
        if (null == tc) {
            TemplateResourceManager.reportNonResource(tmplName);
        }
        return tc;
    }
600269
def find_template_with_lookup(name, prefix = nil, partial = false)
      if prefix == controller_path
        folder = controller.find_inheritable_template_folder(name, partial)
        prefix = folder if folder
      end
      find_template_without_lookup(name, prefix, partial)
    end
1368995
def _resolve_template(value, model_instance=None, context=None):
        """"""
        if isinstance(value, string_types) and "{" in value:
            if context is None:
                context = Context()
            if model_instance is not None:
                context[model_instance._meta.model_name] = model_instance
            value = Template(value).render(context)
        return value
546650
def index_template_exists(name, hosts=None, profile=None):
    '''
    
    '''
    es = _get_instance(hosts, profile)
    try:
        return es.indices.exists_template(name=name)
    except elasticsearch.TransportError as e:
        raise CommandExecutionError("Cannot retrieve template {0}, server returned code {1} with message {2}".format(name, e.status_code, e.error))