0

I created a view block to display a button (join / leave) above my groups. When I add a context filter to my view, it is wrapped in a div without "class" and "id".

1) I added to my view the following context filter:

(Group content User) User: User ID

2) When the filter value is NOT available: Provide a default value: User ID of the logged in user

Here is the result :

<div><section class="views-element-container block block-views block-views-blockgroup-button-rejoindre-ou-quitter-block-1 clearfix" id="block-views-block-group-button-rejoindre-ou-quitter-block-1">



      <div class="form-group"><div class="view view-group-button-rejoindre-ou-quitter view-id-group_button_rejoindre_ou_quitter view-display-id-block_1 js-view-dom-id-7e52cd584bd1944bf2360a966e72384fc9e36069f506a9b448a39dde191c802e">



      <div class="view-empty">
      <a class="btn btn-success" href="/group/2/join"><i class="fa fa-sign-in"></i> Rejoindre le groupe</a>
    </div>

          </div>
</div>

  </section>

</div>

If I delete the context filter, the div envelope would disappear, but that's not the view I want:

<section class="views-element-container block block-views block-views-blockgroup-button-rejoindre-ou-quitter-block-1 clearfix" id="block-views-block-group-button-rejoindre-ou-quitter-block-1">



      <div class="form-group"><div class="view view-group-button-rejoindre-ou-quitter view-id-group_button_rejoindre_ou_quitter view-display-id-block_1 js-view-dom-id-66463110f7422801aaa138cc3887e2da44cb7833e8200c59f0e952de0bc55d5e">



      <div class="view-content">
          <div class="views-row">
    <div class="views-field views-field-id"><span class="field-content btn btn-danger"><a href="/group/2/leave"><i class="fa fa-sign-out"></i> Quitter le groupe</a></span></div>
  </div>
    <div class="views-row">
    <div class="views-field views-field-id"><span class="field-content btn btn-danger"><a href="/group/2/leave"><i class="fa fa-sign-out"></i> Quitter le groupe</a></span></div>
  </div>

    </div>

          </div>
</div>

  </section>

I encounter this problem with other block view, it's really weird. An idea ?

enter image description here

0

Check the twig template (by turning on twig debugging) that is generating the div for your contextual filter. Then alter it with an ID or Class tag.

Let me know if you need help turning on twig debugging.

Find the twig template that is generating that div, copy it and rename it with one of the FILE NAME SUGGESTIONS. The add the following code to the div.

<div{{ attributes.addClass('my-class') }}></div>     
| improve this answer | |
  • I'm guessing you want the"Rejoindre le groupe" button to be on the same line as the other two buttons. This guide will show you how to turn on twig debugging for your local host [link] (chapterthree.com/blog/…). Once you have access to the twig template, simply find the template that is generating that part of your site, it should look like this: <!-- BEGIN OUTPUT from 'themes/custom/[yourthemename]/templates/field/paragraph--text-view-promo.html.twig' --> find that file and update the template via the twig markup language. – ssa4b Jan 24 '18 at 16:11
  • I activated the twig mode in service. You can look at my page again. What must I do now ? I want to delete the div or add a class – Marsouin Jan 25 '18 at 10:40
  • I updated my question with a screenshot – Marsouin Jan 25 '18 at 10:41
  • Looks good. you need to go higher in the document structure and find the twig template that is generating that div. I think it's the template for <div class="region region-content"> on that page. It will say <!-- BEGIN OUTPUT from....] Once you find that, edit the template or create a new twig template by following the naming convention in the <!-- FILE NAME SUGGESTIONS: (the first suggested name is the most specific/targeted) and find the div you want the class added to and apply this code <div{{ attributes.addClass('my-class') }}></div> – ssa4b Jan 25 '18 at 16:18

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.