I created a view template for my website in which i put my exposed form block with twig tweak module. It works when there is at least 1 result. But when my view has no result, the exposed form disappear so i have to reload the page.

 * @file views-bootstrap-grid.html.twig
 * Default simple view template to display Bootstrap Grids.
 * - columns: Contains rows grouped by columns.
 * - rows: Contains a nested array of rows. Each row contains an array of
 *   columns.
 * - column_type: Contains a number (default Bootstrap grid system column type).
 * @ingroup views_templates
  set classes = [
{% if title %}
  <h3>{{ title }}</h3>
{% endif %}
  <h1 class="text-center titreRecherche col-12">Nos formations</h1>
  <p class="text-center " style="letter-spacing: 5px;"> Découvrez toutes les formations proposées par le CFA <p>
<div id="{{ id }}" {{ attributes.addClass(classes) }}>
  <div class="row">
  <div class="sidebar sidebarView col-12 col-sm-12 col-md-4 col-lg-4 col-xl-4 mt-3" >
----->  {{ render_block('formulaireexposerecherche_formationpage_1') }} <---------------
    {% for key, row in rows -%}
      <div {{ row_attributes.addClass(options.row_class) }} >

        <div class="card cardViewRecherche" style="width: 18rem;">
          <h2 class="card-title text-center TypeDiplome"><i class="fas fa-circle" style="font-size: 0.5rem; "></i>{{ view.style_plugin.getField(loop.index0, 'field_type_de_diplome') }}<i class="fas fa-circle" style="font-size: 0.5rem; color: #f7ea48;"></i></h2>
            {{ drupal_field('field_type_de_diplome', 'taxonomy_term', tid) }}
          <h3 class="card-title text-center abreviationView">{{ view.style_plugin.getField(loop.index0, 'field_abreviation_recherche') }}</h3>
          {% set lienContenu = view.style_plugin.getField(loop.index0, 'view_node') %}
          <div class="card-img-top">{{ view.style_plugin.getField(loop.index0, 'field_image_principale') }}</div>
          <div class="card-body bodyRecherche text-center">
            <h3 class="card-title text-center">{{ view.style_plugin.getField(loop.index0, 'field_localisation') }}<i class="fas fa-map-marker-alt" style="font-size: 1.4rem;"></i></h3>
    {% endfor %}

I've tested all the solutions i found on internet but nothing works.

Sorry, I'm beginner on drupal.

Thanks !!

Your Answer

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

Browse other questions tagged or ask your own question.