0

In my twig I use {{ drupal_view('slider', 'block_1', '74,84,82' ) }}, how can I make sure the output of this view has the slides in that specific order?

Currently on D9. I've looked around but can't seem to find any relevant info on how to achieve this. Doesn't seem like this should be that complicated?

1 Answer 1

0

I don't think views is a good choice if you manally want to choose and order items. Views basically is a database query, to be sorted and filtered automatically by a database column (like title field). Instead create the slider markup in the template file, and then render the individual entities by ID (or by IDs sourced and ordered in an entity reference field, if you want to control it in a GUI).

Pseudo-code (using Twig Tweak's drupal_entity):

<div class="my_slider_container">
  <div class="my_slider_item">{{ drupal_entity('node', 74, 'teaser')  }}</div>
  <div class="my_slider_item">{{ drupal_entity('node', 84, 'teaser')  }}</div>
  <div class="my_slider_item">{{ drupal_entity('node', 82, 'teaser')  }}</div>
</div>
1
  • That seems like a better way to set a custom the order, however if possible I'd like to not make too much changes as this is part of a bigger component. I'm currently looking into if it's possible to take the delta-value from the list which the nid (74, 84, 82) are arranged in – However they are nested inside a paragraph which seems to cause issues being able to output values from both the list and the nodes it's referencing, only for that specific page and not all instances of that paragraph. Feels like I'm overcomplicating things though.
    – Lenny
    Oct 6 at 10:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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