【问题标题】:How to display blocks according to the conditions of the current user?如何根据当前用户的条件显示区块?
【发布时间】:2020-03-20 01:37:29
【问题描述】:

我有一个带有 Drupal Commerce 2.14 的 Drupal 8.7 站点

我还安装了 TWIG Tweak 模块。

我想在我的 TWIG 文件中根据当前用户的某些条件显示文本。

感谢您的帮助。

我为我想要的每个条件写一个评论。

这是我页面的代码:

Les étapes pour vendre sur la plateforme

<div class="mb-3">
  {% if logged_in %}
  <i class="fas fa-clipboard-check fa-2x"></i> 
  {% else %}
  <i class="fas fa-clipboard fa-2x"></i> 
  {% endif %}
  Incrivez-vous sur la plateforme
</div>

{# IF THE CURRENT USER TO CREATE A "PRO" TYPE STORE #}
<div class="mb-3">
  {% if ??? %}
  <i class="fas fa-clipboard-check fa-2x"></i> 
  {% else %}
  <i class="fas fa-clipboard fa-2x"></i> 
  {% endif %}
  Créer votre boutique
</div>

<div class="mb-3">
  {% if logged_in %}
  <i class="fas fa-clipboard-check fa-2x"></i> 
  {% else %}
  <i class="fas fa-clipboard fa-2x"></i> 
  {% endif %}
  Créer vos conditions générales de vente
</div>

<div class="mb-3">
  {% if 'marchand_pro' in user.getroles  %}
  <i class="fas fa-clipboard-check fa-2x"></i> 
  {% else %}
  <i class="fas fa-clipboard fa-2x"></i> 
  {% endif %}
  Attendre que l'administrateur de la plateforme valide votre boutique
</div>

{# IF THE CURRENT USER CREATING A PRODUCT IN A "PRO" TYPE STORE #}
<div class="mb-3">
  {% if ??? %}
  <i class="fas fa-clipboard-check fa-2x"></i> 
  {% else %}
  <i class="fas fa-clipboard fa-2x"></i> 
  {% endif %}
  Créer vos produits ou services
</div>

{# IF THE CURRENT USER CREATES A SHIPPING METHOD IN A "PRO" TYPE STORE #}
<div class="mb-3">
  {% if ??? %}
  <i class="fas fa-clipboard-check fa-2x"></i> 
  {% else %}
  <i class="fas fa-clipboard fa-2x"></i> 
  {% endif %}
  Créer les modes de livraison
</div>

{# IF THE CURRENT USER CREATES A PAYMENT GATEWAY IN A "PRO" TYPE STORE #}
<div class="mb-3">
  {% if ??? %}
  <i class="fas fa-clipboard-check fa-2x"></i> 
  {% else %}
  <i class="fas fa-clipboard fa-2x"></i> 
  {% endif %}
  Associer la passerelle de paiement
</div>

<div class="mb-3">
  {% if 'marchand_premium' in user.getroles  %}
  <i class="fas fa-clipboard-check fa-2x"></i> 
  {% else %}
  <i class="fas fa-clipboard fa-2x"></i> 
  {% endif %}
  Activer le compte premium
</div>

【问题讨论】:

    标签: drupal twig drupal-8 drupal-commerce


    【解决方案1】:

    尝试在自定义模块中实现块插件和主题功能。 在块插件的“构建”方法中,添加所有逻辑并将结果作为变量传递给块模板。

    https://www.drupal.org/docs/8/creating-custom-modules/creating-custom-blocks/create-a-custom-block

    【讨论】:

      【解决方案2】:

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-05-27
        • 1970-01-01
        • 1970-01-01
        • 2019-09-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多