0

On my Drupal 8.9 (with Twig Tweak module) home page I integrated a block with the following code :

{{ drupal_view('accueil_page_liste_des_taches_boutique', 'block_1') }}

This block displays the rendered entity (with display mode tasks-frontpage) of the stores of the current user.

I rewrote the display mode of the stores with by creating the following file :

commerce-store--professionnel--tasks-frontpage.html.twig

Here is the file code. All views included in this code have a context filter with the path of the current store :

Vous avez
{% set dangers = 0 %}
{% 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 }}
tâches importantes dans votre {{ store_entity.type.entity.label }} "{{ store_entity.name.value }}".
<a href="/store/{{ store_entity.id }}/tasks" data-drupal-link-system-path="/store/{{ store_entity.id }}/tasks">Voir la liste</a>

MY PROBLEM :

When the {{ drupal_view('accueil_page_liste_des_taches_boutique', 'block_1') }} block is rendered on my home page, the blocks in the commerce-store--professionnel--tasks-frontpage.html.twig templates do not work. This is normal because I think it searches for the store ID in the URL.

How do I fix this ? There is an EVA module, but is there another way to do this directly with TWIG ?

THE OBJECTIVE :

The goal is to create a list of tasks in stores and display it on the user's home page.

The blocks views in the commerce-store--professionnel--tasks-frontpage.html.twig template are used to control this :

  • If the store has no product.
  • If one of the products in the store has no variation.
  • If the store has an order in progress.
  • If the store does not have an associated delivery method.
  • If the store does not have an associated payment gateway.

It may be possible to control this directly in a store template without using views ?

SOLUTION :

Vous avez
{% set dangers = 0 %}
{% if drupal_view_result('boutique_page_liste_des_taches_aucun_produit', 'block_1', store_entity.id()) is empty %}
  {% set dangers = dangers + 1 %}
{% endif %}
{% if drupal_view_result('boutique_page_liste_des_taches_aucune_variation', 'block_1', store_entity.id()) is not empty %}
  {% set dangers = dangers + 1 %}
{% endif %}
{% if drupal_view_result('boutique_page_liste_des_taches_commande', 'block_1', store_entity.id()) is not empty %}
  {% set dangers = dangers + 1 %}
{% endif %}
{% if drupal_view_result('boutique_page_liste_des_taches_mode_de_livraison', 'block_1', store_entity.id()) is empty %}
  {% set dangers = dangers + 1 %}
{% endif %}
{% if drupal_view_result('boutique_page_liste_des_taches_passerelle_de_paiement', 'block_1', store_entity.id()) is empty %}
  {% set dangers = dangers + 1 %}
{% endif %}
{{ dangers }}
tâches importantes à traiter dans votre {{ store_entity.type.entity.label }} "{{ store_entity.name.value }}".
<a href="/store/{{ store_entity.id }}/tasks" data-drupal-link-system-path="/store/{{ store_entity.id }}/tasks">Voir la liste</a>
  • 1
    If you don't want context filters getting IDs from the current path you have to pass arguments to the View, see drupal.stackexchange.com/questions/235812/… – 4k4 Jun 21 at 9:29
  • @4k4 Thanks, I tested this but it doesn't work ('boutique_page_liste_des_taches_aucun_produit', 'block_1', store.id() ) – user99169 Jun 21 at 10:17
  • 1
    @4k4 Ok it works thanks ('boutique_page_liste_des_taches_aucun_produit', 'block_1', store_entity.id()) – user99169 Jun 21 at 10:41
  • Great, put the solution in an answer. – 4k4 Jun 21 at 11:47
0

MY PROBLEM :

When the {{ drupal_view('accueil_page_liste_des_taches_boutique', 'block_1') }} block is rendered on my home page, the blocks in the commerce-store--professionnel--tasks-frontpage.html.twig templates do not work. This is normal because I think it searches for the store ID in the URL.

How do I fix this ? There is an EVA module, but is there another way to do this directly with TWIG ?

If you don't want context filters getting IDs from the current path or current user you have to pass arguments to the View:

{{ drupal_view('accueil_page_liste_des_taches_boutique', 'block_1', store_entity.id()) }}

The arguments can be an array or a scalar if it is only one argument.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy