class documentation

class TemplateCollection(object):

Known subclasses: mako.lookup.TemplateLookup

View In Hierarchy

Represent a collection of .Template objects, identifiable via URI.

A .TemplateCollection is linked to the usage of all template tags that address other templates, such as <%include>, <%namespace>, and <%inherit>. The file attribute of each of those tags refers to a string URI that is passed to that .Template object's .TemplateCollection for resolution.

.TemplateCollection is an abstract class, with the usual default implementation being .TemplateLookup.

Method adjust​_uri Adjust the given uri based on the calling filename.
Method filename​_to​_uri Convert the given filename to a URI relative to this .TemplateCollection.
Method get​_template Return a .Template object corresponding to the given uri.
Method has​_template Return True if this .TemplateLookup is capable of returning a .Template object for the given uri.
def adjust_uri(self, uri, filename):

Adjust the given uri based on the calling filename.

When this method is called from the runtime, the filename parameter is taken directly to the filename attribute of the calling template. Therefore a custom .TemplateCollection subclass can place any string identifier desired in the filename parameter of the .Template objects it constructs and have them come back here.

def filename_to_uri(self, uri, filename):
Convert the given filename to a URI relative to this .TemplateCollection.
def get_template(self, uri, relativeto=None):

Return a .Template object corresponding to the given uri.

The default implementation raises .NotImplementedError. Implementations should raise .TemplateLookupException if the given uri cannot be resolved.

Parameters
uriString URI of the template to be resolved.
relativetoif present, the given uri is assumed to be relative to this URI.
def has_template(self, uri):
Return True if this .TemplateLookup is capable of returning a .Template object for the given uri.
Parameters
uriString URI of the template to be resolved.