Parcourir la source

docs: updated Jinja env

Mikael Koli il y a 3 ans
Parent
commit
529c95109f
1 fichiers modifiés avec 23 ajouts et 4 suppressions
  1. 23 4
      docs/tutorials/templating.rst

+ 23 - 4
docs/tutorials/templating.rst

@@ -5,11 +5,15 @@
 
 .. _templating:
 
-Using Templates
-===============
+Setting Jinja Environments
+==========================
 
-As templating relies on Jinja, you can set the 
-template path to a custom folder and 
+There are two ways of setting a custom Jinja env
+to Red Mail: from paths or directly setting the 
+envs.
+
+To set the paths and let Red Mail to create the 
+environments:
 
 .. code-block:: python
 
@@ -20,6 +24,18 @@ template path to a custom folder and
         text="path/text/templates",
     )
 
+To set the Jinja environments:
+
+.. code-block:: python
+
+    import jinja2
+
+    # Create an env
+    jinja_env = jinja2.Environment(loader=jinja2.FileSystemLoader("path/to/templates"))
+
+    email_sender.templates_html = jinja_env
+    email_sender.templates_text = jinja_env
+
 .. note::
 
     If you are dissatisfied with default HTML and text
@@ -33,6 +49,9 @@ template path to a custom folder and
             html_table="path/html/tables",
             text_table="path/text/tables",
         )
+    
+    The environments are in the attributes ``templates_html_table`` 
+    and ``templates_text_table`` respectively.
 
 Next we will make a simple template, let's call it 
 ``event_card.html``: