How to get current URL in jinja2/flask (request.url not working)
You can use {{ url_for(request.endpoint) }}, it works.
You can use {{ url_for(request.endpoint) }}, it works.
One of the best way to achieve multiple level of templating using jinja2 is to use ‘include’ let say you have ‘base_layout.html‘ as your base template <!DOCTYPE html> <title>Base Layout</title> <div> <h1>Base</h1> …. // write your code here {% block body %}{% endblock %} </div> and then you want to have ‘child_layout.html‘ that extends ‘base_layout. … Read more
I did it like this: {% if var is iterable and (var is not string and var is not mapping) %} You can find a list of all jinja tests here.
Found it. If anyone wants to know: {% if name.endswith(‘-p’) %} {{ name[:-2] }} {% else %} {{ name }} {% endif %}
One way is to wrap the include in a macro, then because the macro is a function, its output can be passed through the indent filter: class MyClass: def someOp(): pass {% macro someop() %}{% include “someOp.html” %}{% endmacro %} {{ someop()|indent }} By default ‘indent’ indents 4 spaces and does not indent the first … Read more
There is whitespace control in Jinja2. You might want: {%- set ip = grains[‘ip4_interfaces’][‘eth1’][0] -%} {%- set domain = pillar[‘company_domain’] -%} {%- set version = pillar[‘site_version’] -%} {%- set site_url=”www.” + domain -%} […] As well, the salt configuration file supports jinja_trim_blocks and jinja_lstrip_blocks (jinja_env:trim_blocks, jinja_env:lstrip_blocks, jinja_sls_env:trim_blocks, and jinja_sls_env:lstrip_blocks as of 2018.3).
Add the following line to your template at first position: #jinja2: trim_blocks:False
I’m a bit late with this answer, but the other solutions don’t really account for your use of Flask. The fact that you’re using Flask with Jinja2 makes your situation a bit different from other frameworks. Flask actually makes some global variables available to you in all Jinja2 templates without requiring you to pass them … Read more
Jinja has multiple ways to control whitespace. It does not have a way to prettify output, you have to manually make sure everything looks “nice”. The broadest solution is to set trim_blocks and lstrip_blocks on the env. app.jinja_env.trim_blocks = True app.jinja_env.lstrip_blocks = True If you want to keep a newline at the end of the … Read more