简体   繁体   English

如何根据当前用户的情况显示区块?

[英]How to display blocks according to the conditions of the current user?

I have a Drupal 8.7 site with Drupal Commerce 2.14我有一个带有 Drupal Commerce 2.14 的 Drupal 8.7 站点

I also installed TWIG Tweak module.我还安装了 TWIG Tweak 模块。

I want to display text based on certain conditions of the current user in my TWIG file.我想在我的 TWIG 文件中根据当前用户的某些条件显示文本。

Thanks for your help.谢谢你的帮助。

I write a comment for each condition I want.我为我想要的每个条件写了一条评论。

Here is the code of my page :这是我的页面的代码:

Les étapes pour vendre sur la plateforme Les étapes pour vendre sur laplateforme

<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>

Try implementing in a custom module a block plugin and a theme function.尝试在自定义模块中实现块插件和主题功能。 In the "build" method of the block plugin, add all your logic and just pass the results as variables to the block template.在块插件的“构建”方法中,添加所有逻辑并将结果作为变量传递给块模板。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM