webrecorder / pywb

Core Python Web Archiving Toolkit for replay and recording of web archives
https://pypi.python.org/pypi/pywb
GNU General Public License v3.0
1.34k stars 207 forks source link

Enable Expression Statement and Loop Control extensions for Jinja templates #844

Open despens opened 1 year ago

despens commented 1 year ago

Is your feature request related to a problem? Please describe.

I want to be able to manipulate lists and dictionaries in pywb templates without the result of the action ("None") needing to be printed. This is accomplished with the do tag which needs to be loaded via the Expression Statement extension.

I want to be able to break out of a loop using the break tag, which needs to be loaded via the the Loop Controls extension.

Describe the solution you'd like

pywb should by default load these basic Jinja extensions.

Describe alternatives you've considered

It is possible to suppress the None output of a list manipulation action using a set capture block:

{% set capture_and_forget %}
    {{ mylist.append('🍄') }}
{% endset %}

However, it would be much nicer to just write

{% do mylist.append('🍄') %}

Likewise it is possible to write logic that can skip steps in a loop. But it would be much easier to just use the {% break %} statement.

Additional context

Let's go nice templates! 😉