The :meth:`jinja2.Environment.compile_expression` method returns an instance of this object. It encapsulates the expression-like access to the template with an expression it wraps.
| 1555 | |
| 1556 | |
| 1557 | class TemplateExpression: |
| 1558 | """The :meth:`jinja2.Environment.compile_expression` method returns an |
| 1559 | instance of this object. It encapsulates the expression-like access |
| 1560 | to the template with an expression it wraps. |
| 1561 | """ |
| 1562 | |
| 1563 | def __init__(self, template: Template, undefined_to_none: bool) -> None: |
| 1564 | self._template = template |
| 1565 | self._undefined_to_none = undefined_to_none |
| 1566 | |
| 1567 | def __call__(self, *args: t.Any, **kwargs: t.Any) -> t.Optional[t.Any]: |
| 1568 | context = self._template.new_context(dict(*args, **kwargs)) |
| 1569 | consume(self._template.root_render_func(context)) |
| 1570 | rv = context.vars["result"] |
| 1571 | if self._undefined_to_none and isinstance(rv, Undefined): |
| 1572 | rv = None |
| 1573 | return rv |
| 1574 | |
| 1575 | |
| 1576 | class TemplateStream: |