Pass the :class:`~jinja2.nodes.EvalContext` as the first argument to the decorated function when called while rendering a template. See :ref:`eval-context`. Can be used on functions, filters, and tests. If only ``EvalContext.environment`` is needed, use :func:`pass_environment`
(f: F)
| 44 | |
| 45 | |
| 46 | def pass_eval_context(f: F) -> F: |
| 47 | """Pass the :class:`~jinja2.nodes.EvalContext` as the first argument |
| 48 | to the decorated function when called while rendering a template. |
| 49 | See :ref:`eval-context`. |
| 50 | |
| 51 | Can be used on functions, filters, and tests. |
| 52 | |
| 53 | If only ``EvalContext.environment`` is needed, use |
| 54 | :func:`pass_environment`. |
| 55 | |
| 56 | .. versionadded:: 3.0.0 |
| 57 | Replaces ``evalcontextfunction`` and ``evalcontextfilter``. |
| 58 | """ |
| 59 | f.jinja_pass_arg = _PassArg.eval_context # type: ignore |
| 60 | return f |
| 61 | |
| 62 | |
| 63 | def pass_environment(f: F) -> F: |