martenframework / marten

The pragmatic web framework.
https://martenframework.com
MIT License
424 stars 24 forks source link

Add a 'with' template tag #86

Closed ellmetha closed 1 year ago

ellmetha commented 1 year ago

Description

Presently, new template variables can be easily assigned from within a template by leveraging the assign template tag. This works fine, but there is presently no way to "locally" define a variable that shouldn't be available to the whole template.

To palliate that, let's introduce a with tag that would work like that:

{% with val1="foo", val2="bar" %}
  {{ val1 }}
  {{ val2 }}
{% endwith %}

The defined variables should only be available within the {% with %}...{% endwith %} tags, which could easily be achieved by leveraging the existing template context stacking capability.