0

I added the List and Grid buttons to the views-view--list_of_products.html.twig twig template of the View:

.....
<div class="product-list-wrapper">
  <div class="exposed-wrapper">
    {{ exposed }}
  </div>
  <div class="rows-wrapper">
    <button onclick="">List</button>
    <button onclick="">Grid</button>

    {% if rows -%}
      {{ rows }}
    {% elseif empty -%}
.....

I need to change the #value of the form field change_view to 'product_card_frontpage' on a click on the Grid button and to change #value to 'product_card_full_width' on a click on the List button:

 if ($form_id == 'views_exposed_form' && $form_state->getStorage('view')['view']->id() == 'list_of_products') {
    $form['change_view'] = [
      '#type' => 'hidden',
      '#value' => 'test',
    ];
  }

0

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.