Substitute special variables that cannot be baked into the template
 because they are dynamically assigned. Only one special variable:

   {stack_name}
186480
def substitute_variables!(properties)
      # transform values and substitute for special values
      # https://stackoverflow.com/questions/34595142/process-nested-hash-to-convert-all-values-to-strings
      #
      # Examples:
      #   "{stack_name}.stag.boltops.com." => development-demo-web.stag.boltops.com.
      #   "{stack_name}.stag.boltops.com." => dev-demo-web-2.stag.boltops.com.
      properties.deep_merge(properties) do |_,_,v|
        if v.is_a?(String)
          v.sub!('{stack_name}', @stack_name) # unsure why need shebang, but it works
        else
          v
        end
      end
      properties
    end
648543
def expand(template, variables=None):
    
    if variables is None:
        variables = {}
    return patterns.sub(functools.partial(_replace, variables), template)
192279
def _parse_template_vars(self):
        
        template_vars = set()
        for var in parsing.find_template_variables(self._code):
            var = var.lstrip('$')
            if var == self.name:
                continue
            if var in ('pre', 'post'):
                raise ValueError('GLSL uses reserved template variable $%s' % 
                                 var)
            template_vars.add(var)
        return template_vars
18622
function modify( &$tpl, &$operatorName, &$operatorParameters, &$rootNamespace, &$currentNamespace, &$operatorValue, &$namedParameters ) {
        switch ($operatorName)
        {
            case 'washxml':
                $operatorValue = str_replace( array( '&', '"', "'", '<', '>' ), array( '&amp;', '&quot;', '&apos;', '&lt;', '&gt;' ), $operatorValue );
                break;
            case 'washxmlcomment':
                // in xml comments the -- string is not permitted
                $operatorValue = str_replace( '--', '_-', $operatorValue );
                break;
            case 'washxmlcdata':
                /// @todo
                eZDebug::writeWarning( 'Template operator washxmlcdata not yet implemented, it should not be used!', __METHOD__ );
                break;
            case 'xsdtype':
                $operatorValue = ggWSDLParser::phpType2xsdType( $operatorValue, $namedParameters['targetprefix'], $namedParameters['xsdprefix'], $namedParameters['soapencprefix'] );
                break;
            case 'classInspect':
                $operatorValue = ggeZWebservices::classInspect( $operatorValue );
                break;
        }
    }
80166
def extract_literal(templatevar):
    
    # FilterExpression contains another 'var' that either contains a Variable or SafeData object.
    if hasattr(templatevar, 'var'):
        templatevar = templatevar.var
        if isinstance(templatevar, SafeData):
            # Literal in FilterExpression, can return.
            return templatevar
        else:
            # Variable in FilterExpression, not going to work here.
            return None

    if templatevar[0] in ('"', "'") and templatevar[-1] in ('"', "'"):
        return templatevar[1:-1]
    else:
        return None
145900
private void copyTagToPageScope(int scope) {
	Iterator iter = null;

	switch (scope) {
	case VariableInfo.NESTED:
	    if (nestedVars != null) {
		iter = nestedVars.iterator();
	    }
	    break;
	case VariableInfo.AT_BEGIN:
	    if (atBeginVars != null) {
		iter = atBeginVars.iterator();
	    }
	    break;
	case VariableInfo.AT_END:
	    if (atEndVars != null) {
		iter = atEndVars.iterator();
	    }
	    break;
	}

	while ((iter != null) && iter.hasNext()) {
	    String varName = (String) iter.next();
	    Object obj = getAttribute(varName);
	    varName = findAlias(varName);
	    if (obj != null) {
		invokingJspCtxt.setAttribute(varName, obj);
	    } else {
		invokingJspCtxt.removeAttribute(varName, PAGE_SCOPE);
	    }
	}
    }
1015127
private void restoreNestedVariables() {
	if (nestedVars != null) {
	    Iterator iter = nestedVars.iterator();
	    while (iter.hasNext()) {
		String varName = (String) iter.next();
		varName = findAlias(varName);
		Object obj = originalNestedVars.get(varName);
		if (obj != null) {
		    invokingJspCtxt.setAttribute(varName, obj);
		} else {
		    invokingJspCtxt.removeAttribute(varName, PAGE_SCOPE);
		}
	    }
	}
    }
1057318
protected String substituteParametersInTemplate(final FunctionTemplate template, final Map<String, String> params) {
        String ret = template.getFiles().get("function.java");
        for (final Map.Entry<String, String> entry : params.entrySet()) {
            ret = ret.replace(String.format("$%s$", entry.getKey()), entry.getValue());
        }
        return ret;
    }
433819
function substiteVariable(variable, options, cb) {
    var value;
    var err = null;
    var s = variable.split(':', 2);
    if (s.length == 2) {
        value = options.env[s[0]];
        if (typeof value == 'function') {
            value = value();
        }
        if (s[1][0] == '+') {
            // Substitute replacement, but only if variable is defined and nonempty. Otherwise, substitute nothing
            value = value ? s[1].substring(1) : '';
        } else if (s[1][0] == '-') {
            // Substitute the value of variable, but if that is empty or undefined, use default instead
            value = value || s[1].substring(1);
        } else if (s[1][0] == '#') {
            // Substitute with the length of the value of the variable
            value = value !== undefined ? String(value).length : 0;
        } else if (s[1][0] == '=') {
            // Substitute the value of variable, but if that is empty or undefined, use default instead and set the variable to default
            if (!value) {
                value = s[1].substring(1);
                options.env[s[0]] = value;
            }
        } else if (s[1][0] == '?') {
            // If variable is defined and not empty, substitute its value. Otherwise, print message as an error message.
            if (!value) {
                if (s[1].length > 1) {
                    throw new Error();
                    // return cb(s[0] + ': ' + s[1].substring(1));
                } else {
                    throw new Error();
                    // return cb(s[0] + ': parameter null or not set');
                }
            }
        }
    } else {
        value = options.env[variable];
        if (typeof value == 'function') {
            value = value();
        }
    }
    return value;
}
1117946
def _build_new_template(self, stack, parameters):
        
        log_lines = ["New template parameters:"]
        for param in sorted(parameters,
                            key=lambda param: param['ParameterKey']):
            log_lines.append("%s = %s" % (param['ParameterKey'],
                                          param['ParameterValue']))

        log_lines.append("\nNew template contents:")
        log_lines.append("".join(stack))
        return log_lines
979334
function(context, args, stack) {
		var xpr = args[0],
			index = args[1],
			templ = args[2],
			val = xpr.__interpolable__ ? xpr.output(context) : xpr,
			rest = new Template(templ._queue.slice(index)),
			instance,
			obj = {
				val: val,
				rest: rest,
				stack: []
			};
		stack.push(obj);
		if (val)
			firstPass(rest, context, obj.stack);
		else if (xpr.__interpolable__)
			instance = xpr.subscribeTo(context, function(value) {
				if (value) {
					obj.val = value;
					instance.destroy();
					firstPass(rest, context, obj.stack);
				}
			});
	}
748736
function buildElementClsBind( def, code, varName ) {
    var attName, attValue, targetAttributeName;
    var result;
    var attribs = {};

    for ( attName in def ) {
        try {
            targetAttributeName = getSuffix( attName, "bind." );
            if ( !targetAttributeName ) continue;

            attValue = def[ attName ];

            if ( isSpecial( attValue ) ) {
                result = { "0": "Bind", "1": def[ attName ][ "0" ] };
                Object.keys( attValue ).forEach( function ( key ) {
                    if ( key == 0 ) return;
                    result[ key ] = attValue[ key ];
                } );
                attribs[ targetAttributeName ] = result;
            } else {
                attribs[ targetAttributeName ] = { "0": "Bind", "1": attValue };
            }
        } catch ( ex ) {
            throw ex + "\n...in tag's bind attribute " + varName + "/" + JSON.stringify( attName );
        }
    }

    return buildElementTagAttribsStandard( attribs, code, varName );
}
598802
private boolean vForVariable(String loopVariablesDefinition, TemplateParserContext context) {
    Matcher matcher = VFOR_VARIABLE.matcher(loopVariablesDefinition);
    if (matcher.matches()) {
      initLoopVariable(matcher.group(1), matcher.group(2), context);
      indexVariableInfo = null;
      return true;
    }

    return false;
  }
312342
private void unExposeVariables() {
        if (deferredExpression == null) {
            // "nested" variables are now simply removed
            if (itemId != null) {
                pageContext.removeAttribute(itemId, PageContext.PAGE_SCOPE);
            }
        } else {
            //we're deferred ... remove variable mapping
            ELContext myELContext = pageContext.getELContext();
            VariableMapper vm = myELContext.getVariableMapper();
            vm.setVariable(itemId, null);
        }
        if (statusId != null) {
            pageContext.removeAttribute(statusId, PageContext.PAGE_SCOPE);
        }
    }
586516
def reloc_var(var_name, reloc_delta, pointer, var_type):
    
    template = '{0} {3}{1} = RELOC_VAR(_{1}, {2}, {0});\n'
    return template.format(
        var_type, var_name, reloc_delta,
        '*' if pointer else ''
    )
268885
def Interpolate(self):
    
    for var_config in collection.DictProduct(self._var_bindings):
      for scope_config in collection.DictProduct(self._scope_bindings):
        subst = Substitution(var_config=var_config, scope_config=scope_config)
        yield subst.Substitute(self._pattern)
331729
def substitute_variables(command, level, name, value, target=None, **kwargs):
    """"""
    rule = kwargs.get('rule', {})
    rule_value = rule.get('value', '') if rule else ''
    substitutes = {
        '${level}': str(level),
        '${target}': str(target),
        '${name}': '"' + str(name) + '"',
        '${value}': str(value),
        '${limit_value}': str(rule_value),
    }

    result = command
    for pattern, value in substitutes.items():
        result = result.replace(pattern, value)

    return result