This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{# použití #} | |
{# import makra, snad by to stačilo jednou v nějakém layoutu #} | |
{% from 'JmNecoBundle::macros.html.twig' import class_attr %} | |
{% set dataZDatabaze = ['prvni', 'druhy', 'treti', 'ctvrty', 'paty'] %} | |
<ul> | |
{% for item in dataZDatabaze %} | |
<li{{ class_attr({'lichy': loop.index is odd, 'posledni': loop.last}) }}>{{ item }}</li> | |
{% endfor %} | |
</ul> | |
{# soubor macros.html.twig #} | |
{% macro class_attr(classes) %} | |
{% set writeTag = true in classes %} | |
{% set needSpace = false %} | |
{% if writeTag %} class="{% for class, enabled in classes %}{% if enabled %}{% if needSpace %} {% endif %}{% set needSpace = true %}{{ class }}{% endif %}{% endfor %}"{% endif %} | |
{% endmacro %} | |
{# což je trochu nepřehledné, kvůli tomu, aby nikde nestrašily mezery #} | |
{# tak to z didaktických důvodů odsadím ;) #} | |
{% macro class_attr(classes) %} | |
{% set writeTag = true in classes %} | |
{% set needSpace = false %} | |
{% if writeTag %} | |
class=" | |
{% for class, enabled in classes %} | |
{% if enabled %} | |
{% if needSpace %} {% endif %} | |
{% set needSpace = true %} | |
{{ class }} | |
{% endif %} | |
{% endfor %} | |
" | |
{% endif %} | |
{% endmacro %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment