asphalt.templating.api

class asphalt.templating.api.TemplateRenderer

Abstract base class for template renderers.

render(template, **vars)

Render the named template.

Parameters:
  • template (str) – name of the template file, relative to any of the configured template directories
  • vars – extra context variables made available to templates
Return type:

str

Returns:

the rendered results

render_string(template, **vars)

Render the template contained in the given string.

Parameters:
  • template (str) – content of the template to render
  • vars – extra variables made available to the template
Return type:

str

Returns:

the rendered results

class asphalt.templating.api.TemplateRendererProxy(ctx: asphalt.core.context.Context, renderer: asphalt.templating.api.TemplateRenderer)

Context-bound template renderer proxy.

Adds the bound context to the variables passed to render() as ctx, unless a variable by that name was explicitly passed.

Any variables and methods provided by the underlying renderer can be directly accessed through this proxy object.

render(template, **vars)

Render the named template.

The current context will be available to the template as the ctx variable.

Parameters:
  • template (str) – name of the template file
  • vars – extra template variables
Return type:

str

Returns:

the rendered results

render_string(source, **vars)

Render the template contained in the given string.

The current context will be available to the template as the ctx variable.

Parameters:
  • source (str) – content of the template to render
  • vars – extra variables made available to the template
Return type:

str

Returns:

the rendered results