-2

I'm a new user of Cement Framework and Python. I try to override the default configuration of jinja2 template handler to set trim_blocks to True. I see the default value of Environment settings in the extension, but I really wonder where is the correct place to override it in Cement ?

Thank you for your help.

Fabd
  • 11
  • 3
  • Does this answer your question? [Remove unnecessary whitespace from Jinja rendered template](https://stackoverflow.com/questions/35775207/remove-unnecessary-whitespace-from-jinja-rendered-template) – Ruli Dec 07 '20 at 11:04
  • Thank you for your answer, but I would to know how override settings in Cement Framework, not directly in template. – Fabd Dec 07 '20 at 15:28

1 Answers1

1

After many tests, I found a way to override Jinja2 extension. I hope it's a good way to do it.

To avoid doing it directly in the command class, I used Cement hook "post_argument_parsing". I've defined this hook in the main class in the file "main.py" like this :

def jinja2_settings_override(self):
   # Jinja2 Environment context
   env = self.output.templater.env
   env.trim_blocks = True

class MyCommandClass(App):
    """Primary application."""

    class Meta:
        label = 'my_command'

        # ... #

        # register the hook to override jinja2 extension settings.
        hooks = [
            ('post_argument_parsing', jinja2_settings_override),
        ]
Fabd
  • 11
  • 3