I
I
Ilya Loopashko2020-10-12 15:17:12
symfony
Ilya Loopashko, 2020-10-12 15:17:12

How to display a post with a condition in Twig?

I need to display a post in a Twig template that has a "Published" checkbox.

<div class="container bg-light">
        {% for posts in post %}
            <div class="row border-bottom pb-2 pt-2">
                <div class="col-md-3"><img src="{{ vich_uploader_asset(posts) }}" class="d-flex mr-3 img-thumbnail" alt="{{ posts.thumbnailFile }}"></div>
                <div class="col-md-9 pt-2">
                    <small><a href="{{ path('category', {'category': posts.category.id }) }}" class="active" role="button" aria-pressed="true">{{ posts.category }}</a></small>
                    <h4 class="mt-0 font-weight-bold"><a href="{{ path('single', {'post': posts.id }) }}">{{ posts.title }}</a></h4>
                    <p class="mb-0"><small><i class="far fa-calendar-alt pr-2"></i>{{ posts.createdAt|date("F jS \\a\\t g:ia") }}</small></p>

                    {% for tag in posts.tags %}
                        <a href="{{ path('tag', {'id': tag.id }) }}" class="btn btn-primary btn-sm active mt-4" role="button" aria-pressed="true">{{ tag }}</a>
                    {% endfor %}
                </div>
            </div>
        {% endfor %}
    </div>


Where to paste

{% if 'published' == true %}

{% endif %}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Komarov, 2020-10-12
@deadloop

Where to paste

To the method of the repository class for receiving data

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question