Twig validator: Shorter IF/FOR syntax
>>> [!note] Migrated issue <!-- Drupal.org comment --> <!-- Migrated from issue #3461538. --> Reported by: [pdureau](https://www.drupal.org/user/1903334) >>> <h3 id="summary-problem-motivation">Problem/Motivation</h3> <p>Twig, Jinja, Nunjucks... allow to replace this annoying syntax;</p> <pre>{% if foo %}<br>{% for item in foo %}<br>{{ item }}<br>{% endfor %}<br>{% else %}<br>&nbsp; No foo<br>{% endif %}</pre><p>by this compact, elegant, syntax:</p> <pre>{% for item in foo %}<br>{{ item }}<br>{% else %}<br>&nbsp; No foo<br>{% endfor %}</pre><p>More generally, without considering the ELSE part, it seems this:</p> <pre>{% if foo %}<br>{% for item in foo %}<br>{{ item }}<br>{% endfor %}<br>{% endif %}</pre><pre>{% if foo is whatever condition %}<br>{% for item in foo %}<br>{{ item }}<br>{% endfor %}<br>{% endif %}</pre><p>can also be written like this:</p> <pre>{% for item in foo %}<br>{{ item }}<br>{% endfor %}</pre><h3 id="summary-proposed-resolution">Proposed resolution</h3> <p>It would be nice to promote it as a good practice.</p> <p>Is it easy to test in ui_patterns_devel's component validator if a IF block has empty text nodes and a FOR block as only child nodes? </p>
issue