stencilproject / Stencil

Stencil is a simple and powerful template language for Swift.
https://stencil.fuller.li
BSD 2-Clause "Simplified" License
2.34k stars 223 forks source link

Break, continue and loops' labels #175

Closed ilyapuchka closed 2 years ago

ilyapuchka commented 6 years ago

This PR adds break and continue tags for loops. They can be labeled, like in Swift, or not.

{% for item in items %}
  {{ item }}{% if condition %}{% break %}{% endif %}
{% endfor %}

Labeled loops:

{% outer: for item in items %}
  {% for key in keys %}
    {{ item.key }}{% if condition %}{% break outer %}{% endif %}
  {% endfor %}
{% endfor %}

Also with labels it's now possible to access outer loop context from inner loop:

{% outer: for item in items %}
  {% for key in keys %}
   {{ forloop.counter }}-{{ forloop.outer.counter }}
  {% endfor %}
{% endfor %}
djbe commented 6 years ago

Before I forget: This PR should document the changes in the docs.

ilyapuchka commented 4 years ago

Is it something we still want to have or it can be closed?

SwiftGen-Eve commented 2 years ago
1 Message
:book: Big PR

Hey 👋 I'm Eve, the friendly bot watching over Stencil 🤖

Thanks a lot for your contribution!


Seems like everything is in order 👍 You did a good job here! 🤝

Generated by :no_entry_sign: Danger