如何使用TWIG创建计数器? [英] How to create a counter with TWIG?

查看:61
本文介绍了如何使用TWIG创建计数器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用Drupal 8的站点,我想用TWIG创建一个任务计数器.

I have a site with Drupal 8 and I want to create a task counter with TWIG.

我使用带有条件的视图.无论视图是否有结果,计数器都必须递增.

I use views with conditions. The counter must be incremented whether the view has a result or not.

这是我刚刚编写的代码:

Here is the code I just made :

<span class="badge badge-warning task-badge-warning">
  {% if drupal_view_result('boutique_page_liste_des_taches_produit_non_publie', 'block_1') is not empty %}
    1
  {% endif %}
  {% if drupal_view_result('boutique_page_liste_des_taches_role_marchand', 'block_1') is empty %}
    1
  {% endif %}
</span>
<span class="badge badge-danger task-badge-danger">
  {% if drupal_view_result('boutique_page_liste_des_taches_aucun_produit', 'block_1') is empty %}
    1
  {% endif %}
  {% if drupal_view_result('boutique_page_liste_des_taches_aucune_variation', 'block_1') is not empty %}
    1
  {% endif %}
  {% if drupal_view_result('boutique_page_liste_des_taches_commande', 'block_1') is not empty %}
    1
  {% endif %}
  {% if drupal_view_result('boutique_page_liste_des_taches_mode_de_livraison', 'block_1') is empty %}
    1
  {% endif %}
  {% if drupal_view_result('boutique_page_liste_des_taches_passerelle_de_paiement', 'block_1') is empty %}
    1
  {% endif %}
</span>

有2个柜台:

  • 警告"徽章
  • 危险"徽章

您知道解决方案吗?

  • 警告"徽章必须显示警告"任务的总数.
  • 危险"标志必须显示危险"任务的总数.

推荐答案

您可以

You can set variables and then increment them:

{% set warnings = 0 %}
<span class="badge badge-warning task-badge-warning">
  {% if drupal_view_result('boutique_page_liste_des_taches_produit_non_publie', 'block_1') is not empty %}
    {% set warnings = warnings + 1 %}
  {% endif %}
  {% if drupal_view_result('boutique_page_liste_des_taches_role_marchand', 'block_1') is empty %}
    {% set warnings = warnings + 1 %}
  {% endif %}
  {{ warnings }}
</span>
{% set dangers = 0 %}
<span class="badge badge-danger task-badge-danger">
  {% if drupal_view_result('boutique_page_liste_des_taches_aucun_produit', 'block_1') is empty %}
    {% set dangers = dangers + 1 %}
  {% endif %}
  {% if drupal_view_result('boutique_page_liste_des_taches_aucune_variation', 'block_1') is not empty %}
    {% set dangers = dangers + 1 %}
  {% endif %}
  {% if drupal_view_result('boutique_page_liste_des_taches_commande', 'block_1') is not empty %}
    {% set dangers = dangers + 1 %}
  {% endif %}
  {% if drupal_view_result('boutique_page_liste_des_taches_mode_de_livraison', 'block_1') is empty %}
    {% set dangers = dangers + 1 %}
  {% endif %}
  {% if drupal_view_result('boutique_page_liste_des_taches_passerelle_de_paiement', 'block_1') is empty %}
    {% set dangers = dangers + 1 %}
  {% endif %}
  {{ dangers }}
</span>

这篇关于如何使用TWIG创建计数器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆