If we find missing variables when rendering a template
    we want to give the user a friendly error
336611
def missing_vars(template_vars, parsed_content, obj):
    """"""
    missing = []
    default_vars = grok_vars(parsed_content)
    for var in template_vars:
        if var not in default_vars and var not in obj:
            missing.append(var)

    if missing:
        e_msg = "Missing required variables %s" % \
                ','.join(missing)
        raise aomi_excep.AomiData(e_msg)
863745
function _renderError(err, request) {
  const error = Boom.boomify(err);
  let status = error.output.statusCode;
  let rendered;
  let errorFile;

  if (this.local && status !== 404) {
    errorFile = resolve(dashboard.paths.views, 'errors', 'trace.html');
    rendered = Template.fromFile(errorFile).render({
      error: {
        status,
        title: error.output.payload.error,
        message: error.message,
        stack: error.stack,
      },
      request,
    });
  } else {
    const siteFile = resolve(this.paths.www, '_error.html');
    status = status === 404 ? 404 : 500;
    errorFile = status === 404 && fs.existsSync(siteFile) ? siteFile : resolve(dashboard.paths.views, 'errors', `${status}.html`);
    rendered = fs.readFileSync(errorFile, 'utf-8');
  }

  if (status !== 404) {
    Logger.extra(error.stack);
  }

  return [status, rendered];
}
817534
def render_to_string(self, template, context=None, def_name=None, subdir='templates'):
        ''''''
        template_adapter = self.get_template_loader(subdir).get_template(template)
        return getattr(template_adapter, 'render')(context=context, request=self.request, def_name=def_name)
887902
private function _getRequiredVars( $template_identifier )
	{
		if ( !( isset( $this->_available_templates[$template_identifier] ) ) )
		{
			trigger_error( "Template identifier not found.", E_USER_ERROR );
		}

		$template_path = ROOT_PATH.'/'.$this->_available_templates[$template_identifier];

		if ( !( $template_source = file_get_contents( $template_path ) ) )
		{
			trigger_error( "{$template_path} not found.", E_USER_ERROR );
		}

		if ( !( preg_match_all( '/{.*\$([a-z_\-]*).*}/', $template_source, $matchs) ) )
		{
			trigger_error( "Not found in use vars in the tpl source.", E_USER_WARNING );
		}

		$required_vars = array_unique( $matchs[1] );

		// Remove url.
		unset( $required_vars[array_search( 'url', $required_vars )] );

		return $required_vars;
	}
722329
final ParseErrorDetails renderError() {
    final int errorIndex = toIndex(currentErrorAt);
    final String encounteredName = getEncountered();
    final ArrayList<String> errorStrings = Lists.arrayList(errors.size());
    for (Object error : errors) {
      errorStrings.add(String.valueOf(error));
    }
    switch (currentErrorType) {
    case UNEXPECTED :
      return new EmptyParseError(errorIndex, encounteredName) {
        @Override public String getUnexpected() {
          return errorStrings.get(0);
        }
      };
    case FAILURE :
      return new EmptyParseError(errorIndex, encounteredName) {
        @Override public String getFailureMessage() {
          return errorStrings.get(0);
        }
      };
    case EXPECTING:
    case MISSING:
    case DELIMITING:
      return new EmptyParseError(errorIndex, encounteredName) {
        @Override public List<String> getExpected() {
          return errorStrings;
        }
      };
    default:
      return new EmptyParseError(errorIndex, encounteredName);
    }
  }
1073747
def error_view(template_dir=None):
    
    if not template_dir:
        template_dir = "Pylot/Error"

    template_page = "%s/index.html" % template_dir

    class Error(Pylot):
        """
        Error Views
        """
        @classmethod
        def register(cls, app, **kwargs):
            super(cls, cls).register(app, **kwargs)

            @app.errorhandler(400)
            def error_400(error):
                return cls.index(error, 400)

            @app.errorhandler(401)
            def error_401(error):
                return cls.index(error, 401)

            @app.errorhandler(403)
            def error_403(error):
                return cls.index(error, 403)

            @app.errorhandler(404)
            def error_404(error):
                return cls.index(error, 404)

            @app.errorhandler(500)
            def error_500(error):
                return cls.index(error, 500)

            @app.errorhandler(503)
            def error_503(error):
                return cls.index(error, 503)

        @classmethod
        def index(cls, error, code):
            cls.meta_(title="Error %s" % code)

            return cls.render(error=error, view_template=template_page), code
    return Error
194921
function renderTemplate(template, locals, cb) {
    var res;

    try {
      var localTemplateOptions = self.getLocalTemplateOptions(locals);
      var localsClone = _.extend({}, locals);
      self.updateLocalTemplateOptions(localsClone, undefined);
      res = template(localsClone, _.merge({}, self._options.templateOptions, localTemplateOptions));
    } catch (err) {
      if (err.message) {
        err.message = '[' + template.__filename + '] ' + err.message;
      } else if (typeof err === 'string') {
        return cb('[' + template.__filename + '] ' + err, null);
      }
      return cb(err, null);
    }
    cb(null, res);
  }
1142047
function render(engine, str, locals, engineOptions) {
  try {
    var output = engine.render(engine.engine, str, locals, engineOptions)
  } catch(e) {
    throw new Error(
      NAME + ': there was a problem rendering the template:\n' + e)
  }
  return output
}
1296600
def validate_template_syntax(source):
    
    try:
        Template(source)
    except (TemplateSyntaxError, TemplateDoesNotExist) as err:
        raise ValidationError(text_type(err))
1088245
def resolve(self, var, context):
        """"""
        if var is None:
            return var
        if var[0] in ('"', "'") and var[-1] == var[0]:
            return var[1:-1]
        else:
            return template.Variable(var).resolve(context)
610854
def setup_errors(app, error_template="error.html"):
    """"""
    def error_handler(error):
        if isinstance(error, HTTPException):
            description = error.get_description(request.environ)
            code = error.code
            name = error.name
        else:
            description = error
            code = 500
            name = "Internal Server Error"
        return render_template(error_template,
                               error=error,
                               code=code,
                               name=Markup(name),
                               description=Markup(description)), code

    for exception in default_exceptions:
        app.register_error_handler(exception, error_handler)
17424
def render(self, name, context):
        """"""
        if Generator.strict:
            self.env.undefined = TestableUndefined
        else:
            self.env.undefined = Undefined
        template = self.get_template(name)
        return template.render(context)
1217547
protected function renderError()
    {
        $errMessage = $this->errMessage;
        $errFile = $this->errFile;
        $errLine = $this->errLine;

        \ob_start();
        require __DIR__ . '/templates/trace.error.phtml';

        return \ob_get_clean();
    }
1220787
def render(self, name, value, attrs=None, renderer=None):
        """"""
        location = getattr(value, '_seralized_location', '')
        if location and not hasattr(value, 'url'):
            value.url = '#'
            if hasattr(self, 'get_template_substitution_values'):
                # Django 1.8-1.10
                self.template_with_initial = (
                    '%(initial_text)s: %(initial)s %(clear_template)s'
                    '<br />%(input_text)s: %(input)s')
        attrs = attrs or {}
        attrs.update({'data-upload-url': self.url})
        hidden_name = self.get_hidden_name(name)
        kwargs = {}
        if django_version >= (1, 11):
            kwargs['renderer'] = renderer

        parent = super(StickyUploadWidget, self).render(name, value, attrs=attrs, **kwargs)
        hidden = forms.HiddenInput().render(hidden_name, location, **kwargs)

        return mark_safe(parent + '\n' + hidden)
887772
def as_crispy_errors(form, template_pack=TEMPLATE_PACK):
    
    if isinstance(form, BaseFormSet):
        template = get_template('%s/errors_formset.html' % template_pack)
        c = Context({'formset': form}).flatten()
    else:
        template = get_template('%s/errors.html' % template_pack)
        c = Context({'form': form}).flatten()

    return template.render(c)
996801
def debug_variable_node_render(self, context):
    
    try:
        output = self.filter_expression.resolve(context)
        output = template_localtime(output, use_tz=context.use_tz)
        output = localize(output, use_l10n=context.use_l10n)
        output = force_text(output)
    except Exception as e:
        if not hasattr(e, 'django_template_source'):
            e.django_template_source = self.source
        raise
    if (context.autoescape and not isinstance(output, SafeData)) or isinstance(output, EscapeData):  # nopep8
        return escape(output)
    else:
        return output
498783
def substitute_vars(template, replacements):
    
    result = template
    for (key, value) in replacements:
        result = result.replace('${' + key + '}' , value)
    if '${' in result:
        logging.warning("A variable was not replaced in '%s'.", result)
    return result