Skip to content

environment (1)

template

template(self, template: str | os.PathLike[str]) -> bool

Check whether given template path exists.

Example

Jinja call:

{% if "filters.md" is template %}
True!
{% endif %}
Result:

DocStrings

Parameters:

Name Type Description Default
template str | PathLike[str]

The template path to check

required

Returns:

Type Description
bool

True if the template exists, False otherwise.

Source code in src/jinjarope/environment.py
126
127
128
129
130
131
132
133
134
135
def __contains__(self, template: str | os.PathLike[str]) -> bool:
    """Check whether given template path exists.

    Args:
        template: The template path to check

    Returns:
        True if the template exists, False otherwise.
    """
    return pathlib.Path(template).as_posix() in self.list_templates()