How to use flags with Twig ?

Created on 9 April 2018, over 6 years ago
Updated 13 September 2023, about 1 year ago

I have customized the commerce-product.html.twig template of "Drupal Commerce".

I want to display in this file:

1) the flag link (flagged / deflagued).
2) the number of flags on the product.

I managed to display the drapreau link (flagged / deflagated) in twig, but if I created a view that displays all the products with my custom view, the flag link is the link of the page.
This is not correct, the flag link should be the link of the produced entity.
How to display the right link?

I can not get the number of flags on the product.
How to do this ?

<article{{ attributes }}>

  <div class="view-teaser-produit">
    <div class="views-row">

      <div class="views-teaser-type">
        Produit
      </div>

      <div class="views-teaser-image">
        {{ product.field_produit_image.0 }}
      </div>

      <h3 class="views-teaser-title">
        {{ product.title }}
      </h3>

      <div class="views-teaser-variation">
        {{ product.variation_price }}
        {{ product.variations }}
      </div>

      <div class="views-teaser-like-count">
        <span class="fa-layers fa-fw">
          <i class="fas fa-bookmark"></i>
          <span class="fa-layers fa-fw">
            <i class="fas fa-heart"></i>
            <span class="fa-layers-text">{{ product.flag_like_product.count }}</span>
          </span>
        </span>
      </div>

      <div class="views-teaser-like-link">
        {{ product.flag_like_product }}
      </div>

      {{ product.stores }}

      <div class="views-teaser-more-link">
        Voir la fiche produit
      </div>

      <div class="views-teaser-link">
        <a href="{{ product_url }}" title="{{ product_entity.title.value }}"></a>
      </div>

    </div>
  </div>

</article>
💬 Support request
Status

Active

Version

4.0

Component

Flag core

Created by

🇫🇷France zenimagine

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024