Extra context for email templates

Issue #131 resolved
Meiyer created an issue

I need a way to be able to provide extra context to the templates used in email notifications. A setting for a callable receiving Postman’s context and returning extra_context (used while rendering the 3 templates by render_to_string in the email() utility) would work.

Comments (3)

  1. Patrick Samson repo owner
    • changed status to open

    Are you OK with this anticipated documentation? (similar to POSTMAN_PARAMS_EMAIL)

    POSTMAN_CONTEXT_EMAIL

    *New in version 4.4.*
    
    You can extend the context used to build the parts of emails (template renderings, from, sending params).
    The value can be specified as:
    
    * A function.
    * The full path to a function, as a string, whose import will be deferred. For example: 'myapp.mymodule.myfunc'.
    
    In both cases, the function receives one parameter: a dictionary with the default context variables
    as stated in section :ref:`for_visitors`, that is: {'site': ..., 'object': ..., 'action': ...}.
    The return must be, either the dictionary given as parameter, either a new one, containing probably the previous keys
    and possibly new ones.
    
    *Defaults to*: None.
    
    Example::
    
        def get_context_email(context):
            context['my-key'] = 'my-value'
            return context
        POSTMAN_CONTEXT_EMAIL = get_context_email  # default is None
    
  2. Meiyer reporter

    The description looks good to me! I think the “defaults to” part could be made clearer (that when None the templates will receive the default context). Also the wording of the “return” part feels a bit convoluted.

  3. Log in to comment