*************************\
Creates the template loader
Then the template engine & adds its extensions
357260
public function setTemplate()
    {
        // Creates the loader & sets the template directory path
        $loader = new FilesystemLoader('../src/View');

        // Creates the template engine
        $twig = new Environment($loader, array(
            'cache' => false,
            'debug' => true
        ));

        // Adds Twig extensions
        $twig->addExtension(new DebugExtension());
        $twig->addExtension(new PamTwigExtension());

        // Attributes the template engine to the current object
        $this->twig = $twig;
    }
234284
function (options, file, callback) {
  options.logger('Generating template from ' + file)

  async.waterfall([
    async.apply(fs.readFile, file),
    function (template, callback) {
      var result = _.template(template)(options)
      options.logger('Generated template from ' + file + '\n' + result)
      callback(null, result)
    }
  ], callback)
}
1226660
function buildTemplate(){
    // build new declaration
    var declaration = getDeclFromSource(this.source, this.baseURI, false, {
      isolate: this.getIsolatePrefix()
    });

    // make functions and assign to template
    var destroyBuilder = this.destroyBuilder;
    var instances = {};
    var funcs = this.builder(declaration.tokens, instances);
    this.createInstance = funcs.createInstance;
    this.clearInstance = funcs.destroyInstance;
    this.destroyBuilder = funcs.destroy;

    store.add(this.templateId, this, instances);

    // for debug purposes only
    /** @cut */ this.instances_ = instances;
    /** @cut */ this.decl_ = declaration;


    // process dependencies
    var newDeps = declaration.deps;
    var oldDeps = this.deps_;
    this.deps_ = newDeps;

    // detach old deps
    if (oldDeps)
      for (var i = 0, dep; dep = oldDeps[i]; i++)
        dep.bindingBridge.detach(dep, templateSourceUpdate, this);

    // attach new deps
    if (newDeps)
      for (var i = 0, dep; dep = newDeps[i]; i++)
        dep.bindingBridge.attach(dep, templateSourceUpdate, this);


    // apply resources
    // start use new resource list and than stop use old resource list,
    // in this order FOUC is less possible
    var newResources = declaration.resources;
    var oldResources = this.resources;
    this.resources = newResources;

    if (newResources)
      for (var i = 0, item; item = newResources[i]; i++)
      {
        var resource = basis.resource(item.url).fetch();
        if (typeof resource.startUse == 'function')
          resource.startUse();
      }

    if (oldResources)
      for (var i = 0, item; item = oldResources[i]; i++)
      {
        var resource = basis.resource(item.url).fetch();
        if (typeof resource.stopUse == 'function')
          resource.stopUse();
      }


    // destroy old instances if any
    if (destroyBuilder)
      destroyBuilder(true);
  }
255910
static void visitTemplateLiteral(NodeTraversal t, Node n, boolean addTypes) {
    JSTypeRegistry registry = t.getCompiler().getTypeRegistry();
    JSType stringType = createType(addTypes, registry, JSTypeNative.STRING_TYPE);
    int length = n.getChildCount();
    if (length == 0) {
      n.replaceWith(withType(IR.string("\"\""), stringType));
    } else {
      Node first = n.removeFirstChild();
      checkState(first.isTemplateLitString() && first.getCookedString() != null);
      Node firstStr = withType(IR.string(first.getCookedString()), stringType);
      if (length == 1) {
        n.replaceWith(firstStr);
      } else {
        // Add the first string with the first substitution expression
        Node add =
            withType(IR.add(firstStr, n.removeFirstChild().removeFirstChild()), n.getJSType());
        // Process the rest of the template literal
        for (int i = 2; i < length; i++) {
          Node child = n.removeFirstChild();
          if (child.isTemplateLitString()) {
            checkState(child.getCookedString() != null);
            if (child.getCookedString().isEmpty()) {
              continue;
            } else if (i == 2 && first.getCookedString().isEmpty()) {
              // So that `${hello} world` gets translated into (hello + " world")
              // instead of ("" + hello + " world").
              add = add.getSecondChild().detach();
            }
          }
          add =
              withType(
                  IR.add(
                      add,
                      child.isTemplateLitString()
                          ? withType(IR.string(child.getCookedString()), stringType)
                          : child.removeFirstChild()),
                  n.getJSType());
        }
        n.replaceWith(add.useSourceInfoIfMissingFromForTree(n));
      }
    }
    t.reportCodeChange();
  }
169911
function compile(template, context) {
        for (var name in context) {
            template = template.replace('{{' + name + '}}', context[name])
        }
        return template
    }
1122908
def add_template(template, **kwargs):
    
    tmpl = Template()
    tmpl.name = template.name
    if template.description:
        tmpl.description = template.description
    if template.layout:
        tmpl.layout = get_layout_as_string(template.layout)

    db.DBSession.add(tmpl)

    if template.templatetypes is not None:
        types = template.templatetypes
        for templatetype in types:
            ttype = _update_templatetype(templatetype)
            tmpl.templatetypes.append(ttype)

    db.DBSession.flush()
    return tmpl
1005507
function loadTemplate(templatePath, identifier) {
  return plugin.myrmex.fire('beforeTemplateLoad', templatePath, identifier)
  .spread((templatePath, name) => {
    const templateDoc = _.cloneDeep(require(path.join(templatePath)));

    // Lasy loading because the plugin has to be registered in a Myrmex instance before requiring the document
    const Template = require('./template');
    const template = new Template(templateDoc, identifier);

    // This event allows to inject code to alter the template configuration
    return plugin.myrmex.fire('afterTemplateLoad', template);
  })
  .spread(template => {
    return Promise.resolve(template);
  });
}
1086048
public function init_template_loader() {
		$loader_class  = $this->hasConfigKey( 'template', 'custom_loader' )
			? $this->getConfigKey( 'template', 'custom_loader' )
			: $this->get_default_template_loader_class();
		$filter_prefix = $this->hasConfigKey( 'template', 'filter_prefix' )
			? $this->getConfigKey( 'template', 'filter_prefix' )
			: $this->get_default_filter_prefix();
		$template_dir  = $this->hasConfigKey( 'template', 'template_directory' )
			? $this->getConfigKey( 'template', 'template_directory' )
			: $this->get_default_template_directory();
		$view_dir      = $this->hasConfigKey( 'view' )
			? $this->get_directory_from_view( $this->getConfigKey( 'view' ) )
			: $this->get_default_view_directory();

		return new $loader_class(
			$filter_prefix,
			$template_dir,
			$view_dir
		);
	}
518120
function templateSourceUpdate(){
    if (this.destroyBuilder)
      buildTemplate.call(this);

    var cursor = this;
    while (cursor = cursor.attaches_)
      cursor.handler.call(cursor.context);
  }
844497
function Template (filename, context) {
    // Save the context for reuse in sub-templates
    this.context = context || {}
    this.context.include = this.render.bind(this)
    this.context.forEach = forEach

    // Save the filename for the initial render
    this.filename = filename

    // Create a cache so we only read files once
    this.cache = {}
}
7151
public function loadCompiler()
    {
        if (!class_exists($this->source->handler->compiler_class)) {
            $this->smarty->loadPlugin($this->source->handler->compiler_class);
        }
        $this->compiler = new $this->source->handler->compiler_class($this->source->handler->template_lexer_class,
                                                                     $this->source->handler->template_parser_class,
                                                                     $this->smarty);
    }
214756
function(options) {
        options = this.setOptions(options);
        this.element = this.createElement();

        // Generate loader elements
        this.loader = this.render(options.loaderTemplate).appendTo(this.element);
        this.message = this.loader.find(this.ns('message', 'loader'));

        if (options.showLoading) {
            this.message.html(Toolkit.messages.loading);
        }

        // Initialize
        this.initialize();
    }
920746
function(callback) {
		// TODO: don't wait until the end. Instead, emit immediately upon finding the template

		if (!templateFile) throw new Error('template not found in stream');

		templateFile.data = templateFile.data || {};

		files.forEach(function(file) {
			var newFile = templateFile.clone();

			newFile.data.file = file;
			newFile.path = file.path;

			this.push(newFile);
		}, this);

		callback();
	}
926168
def generate_loader(self, mapfile, names):
        
        return self.build_template(mapfile, names, self._loaddata_template)
954011
public static function init()
    {
        self::$loader = new Twig_Loader_Filesystem();

        $config = Config::getInstance();

        foreach (array_reverse($config->get('Octo.paths.templates', [])) as $path) {
            self::$loader->addPath($path);
        }

        foreach (array_reverse($config->get('Octo.paths.admin_templates', [])) as $path) {
            self::$loader->addPath($path, 'admin');
        }

        self::$loader->addPath(CMS_PATH . 'Database/Templates/', 'db');

        if (OCTO_CACHE_ENABLED) {
            self::$cache = OCTO_CACHE_PATH;
        } else {
            self::$cache = false;
        }

        self::$twig = new Twig_Environment(self::$loader, [
            'charset' => 'UTF-8',
            'cache' => self::$cache,
            'auto_reload' => true,
            'strict_variables' => false,
        ]);

        $functions = [];
        Event::trigger('TemplateInit', $functions);

        foreach ($functions as $name => $callable) {
            self::addFunction($name, $callable);
        }

        self::$initialised = true;
    }
419681
public void loadTemplates() throws TemplateException {
        loadStrategyI.loadTemplates();
        this.templateSet = loadStrategyI.getTemplates();
        this.templateOrders = loadStrategyI.getOrders();
    }
311288
def install_templates(srcroot, destroot, prefix='', excludes=None,
                      includes=None, path_prefix=None):
    #pylint:disable=too-many-arguments,too-many-statements
    
    #pylint: disable=too-many-locals
    if excludes is None:
        excludes = []
    if includes is None:
        includes = []
    if not os.path.exists(os.path.join(prefix, destroot)):
        os.makedirs(os.path.join(prefix, destroot))
    for pathname in os.listdir(os.path.join(srcroot, prefix)):
        pathname = os.path.join(prefix, pathname)
        excluded = False
        for pat in excludes:
            if re.match(pat, pathname):
                excluded = True
                break
        if excluded:
            for pat in includes:
                if re.match(pat, pathname):
                    excluded = False
                    break
        if excluded:
            LOGGER.debug("skip %s", pathname)
            continue
        source_name = os.path.join(srcroot, pathname)
        dest_name = os.path.join(destroot, pathname)
        if os.path.isfile(source_name) and not os.path.exists(dest_name):
            # We don't want to overwrite specific theme files by generic ones.
            with open(source_name) as source:
                template_string = source.read()
            try:
                template_string = force_text(template_string)
                lexer = DebugLexer(template_string)
                tokens = lexer.tokenize()
                if not os.path.isdir(os.path.dirname(dest_name)):
                    os.makedirs(os.path.dirname(dest_name))
                engine, libraries, builtins = get_html_engine()
                if isinstance(engine, DjangoTemplates):
                    with open(dest_name, 'w') as dest:
                        parser = AssetsParser(tokens,
                            URLRewriteWrapper(dest, path_prefix),
                            libraries=libraries,
                            builtins=builtins,
                            origin=None)
                        parser.parse_through()
                else:
                    template_name = None
                    tokens = Lexer(engine.env).tokeniter(template_string,
                        template_name, filename=source_name)
                    buffered_tokens = []
                    state = None
                    with open(dest_name, 'w') as dest:
                        for token in tokens:
                            if state is None:
                                if token[1] == 'block_begin':
                                    state = STATE_BLOCK_BEGIN
                            elif state == STATE_BLOCK_BEGIN:
                                if token[1] == 'name':
                                    if token[2] == 'assets':
                                        state = STATE_ASSETS_BEGIN
                                    else:
                                        buffered_tokens += [token]
                                        state = None
                            elif state == STATE_ASSETS_BEGIN:
                                if (token[1] == 'name'
                                    and token[2] == 'endassets'):
                                    state = STATE_ASSETS_END
                            elif state == STATE_ASSETS_END:
                                if token[1] == 'block_end':
                                    buffered_tokens += [token]
                                    state = None
                            if state is None:
                                if buffered_tokens:
                                    for tok in buffered_tokens:
                                        if (tok[1] == 'name' and
                                            tok[2] == 'assets'):
                                            dest.write(_render_assets(
                                                buffered_tokens,
                                                engine.env.assets_environment))
                                            buffered_tokens = []
                                            break
                                    if buffered_tokens:
                                        dest.write("%s" % ''.join([token[2]
                                            for token in buffered_tokens]))
                                    buffered_tokens = []
                                else:
                                    dest.write("%s" % str(token[2]))
                            else:
                                buffered_tokens += [token]
                        if buffered_tokens:
                            dest.write("%s" % ''.join([
                                token[2] for token in buffered_tokens]))
                            buffered_tokens = []
                        dest.write("\n")

                cmdline = ['diff', '-u', source_name, dest_name]
                cmd = subprocess.Popen(cmdline, stdout=subprocess.PIPE)
                lines = cmd.stdout.readlines()
                cmd.wait()
                # Non-zero error codes are ok here. That's how diff
                # indicates the files are different.
                if lines:
                    verb = 'compile'
                else:
                    verb = 'install'
                dest_multitier_name = dest_name.replace(destroot,
                        '*MULTITIER_TEMPLATES_ROOT*')
                LOGGER.debug("%s %s to %s", verb,
                    source_name.replace(
                        django_settings.BASE_DIR, '*APP_ROOT*'),
                    dest_multitier_name)
            except UnicodeDecodeError:
                LOGGER.warning("%s: Templates can only be constructed "
                    "from unicode or UTF-8 strings.", source_name)
        elif os.path.isdir(source_name):
            install_templates(srcroot, destroot, prefix=pathname,
                excludes=excludes, includes=includes, path_prefix=path_prefix)