Hi,

I just installed the module is it is really excellent. I created a view with two block display. The first block displays my content and the second one displays nothing, just a header with the following code :

<div class="panel-group" id="accordion">
  <div class="panel panel-default">
    <div class="panel-heading">
      <h4 class="panel-title">
        <a data-toggle="collapse" data-parent="#accordion" href="#collapse1">
        <i class="fa fa-object-group fa-lg"></i> Ses contenus (<dd>{{ drupal_view('profil_page_contenu_utilisateur', 'block_1', '@total') }}</dd>)</a>
      </h4>
    </div>
    <div id="collapse1" class="panel-collapse collapse">
      <div class="panel-body"><dd>{{ drupal_view('profil_page_contenu_utilisateur', 'block_1') }}</dd></div>
    </div>
  </div>
</div>

With the following line of code :

<i class="fa fa-object-group fa-lg"></i> Ses contenus (<dd>{{ drupal_view('profil_page_contenu_utilisateur', 'block_1', '@total') }}</dd>)</a>

How to retrieve the element number of a view (block_1) ?

Comments

zenimagine created an issue. See original summary.

chi’s picture

Title: How to retrieve the element number of a view ? » How to retrieve the element number of a view?
Status: Active » Fixed

How to retrieve the element number of a view (block_1) ?

I am not sure I understand the question correctly. Guess you need to add a hidden field to the view that would hold the element number. Views provides counter field type for this purpose.

zenimagine’s picture

I created a view of my products. I added in the header of the view "Global: Result summary (Global: Result summary)" with the token "@total".

I created a second view and I want to display the product number of my first view in it.

I installed the https://www.drupal.org/project/twig_tweak module

I added a field "Configure field: Global: Custom text" to my second view, with <dd>{{ drupal_view('boutique_page_produit', 'block_2') }}</dd> My first view is well displayed in it.

What I am trying to do :

I do not want to display the first view in the second, I only want to display "Global: Result summary (Global: Result summary)" with the token "@total" in my second view.

How to do this ?

zenimagine’s picture

Status: Fixed » Active
chi’s picture

Still not sure I understand the question correctly. However you might not need Tweak tweak module for this task if you use aggregation option of the view. Another possible solution is using drupal_view_result() Twig function.
{{ drupal_view_result(view_id)|length }}

zenimagine’s picture

StatusFileSize
new85.71 KB
new132 KB
zenimagine’s picture

@Chi

Watch the last 2 screenshots.

  • view-1.png show my products
  • in view-2.png I want to display the product number of view-1.png

If I put the code:

<dd>{{ drupal_view('boutique_page_produit', 'block_2') }}</dd>

view-2.png will show all my view-1.png (I only want the number of product)

chi’s picture

Issue summary: View changes

#5 should work for you.

zenimagine’s picture

@Chi

<dd>{{ drupal_view('boutique_page_produit', 'block_2') }}</dd>

{{ drupal_view_result(view_id)|length }}

thank you, taking my current code and your code is correct :

<dd>{{ drupal_view_result('boutique_page_produit', 'block_2')|length }}</dd>

zenimagine’s picture

I confirm it works. Thank you

zenimagine’s picture

Status: Active » Fixed
chi’s picture

Just to be clear, you should not put <dd/> tags to your snippet. They make not sense in this context.

zenimagine’s picture

On my view I use pagination. My problem :

If I have 4 pages with my view

{{ drupal_view_result('boutique_page_produit', 'block_2')|length }}

displays the number of items in the page. I want the total slice number of the view (not just the page).

chi’s picture

I think you have to create another view without pagination.

zenimagine’s picture

OK, thanks

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.