Get the template source, filename and reload helper for a template. It's passed the environment and template name and has to return a tuple in the form ``(source, filename, uptodate)`` or raise a `TemplateNotFound` error if it can't locate the template. The source pa
(
self, environment: "Environment", template: str
)
| 73 | has_source_access = True |
| 74 | |
| 75 | def get_source( |
| 76 | self, environment: "Environment", template: str |
| 77 | ) -> t.Tuple[str, t.Optional[str], t.Optional[t.Callable[[], bool]]]: |
| 78 | """Get the template source, filename and reload helper for a template. |
| 79 | It's passed the environment and template name and has to return a |
| 80 | tuple in the form ``(source, filename, uptodate)`` or raise a |
| 81 | `TemplateNotFound` error if it can't locate the template. |
| 82 | |
| 83 | The source part of the returned tuple must be the source of the |
| 84 | template as a string. The filename should be the name of the |
| 85 | file on the filesystem if it was loaded from there, otherwise |
| 86 | ``None``. The filename is used by Python for the tracebacks |
| 87 | if no loader extension is used. |
| 88 | |
| 89 | The last item in the tuple is the `uptodate` function. If auto |
| 90 | reloading is enabled it's always called to check if the template |
| 91 | changed. No arguments are passed so the function must store the |
| 92 | old state somewhere (for example in a closure). If it returns `False` |
| 93 | the template will be reloaded. |
| 94 | """ |
| 95 | if not self.has_source_access: |
| 96 | raise RuntimeError( |
| 97 | f"{type(self).__name__} cannot provide access to the source" |
| 98 | ) |
| 99 | raise TemplateNotFound(template) |
| 100 | |
| 101 | def list_templates(self) -> t.List[str]: |
| 102 | """Iterates over all templates. If the loader does not support that |