簡體   English   中英

如何根據當前用戶的情況顯示區塊?

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

我有一個帶有 Drupal Commerce 2.14 的 Drupal 8.7 站點

我還安裝了 TWIG Tweak 模塊。

我想在我的 TWIG 文件中根據當前用戶的某些條件顯示文本。

謝謝你的幫助。

我為我想要的每個條件寫了一條評論。

這是我的頁面的代碼:

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>

嘗試在自定義模塊中實現塊插件和主題功能。 在塊插件的“構建”方法中,添加所有邏輯並將結果作為變量傳遞給塊模板。

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