0

I have a View which display the title field of content of the type Partners. However, I want to format the results in a drop-down select list, so when a user selects one of the titles, it will automatically redirect the user to the content page. How can I achieve this?

2
  • 1
    I think this is possible but not with Views. If I had to, I'd do that programmatically with a query to populate a select in a form...
    – Djouuuuh
    Oct 29, 2014 at 10:12
  • 1
    It can be done by manipulating the views templates, in particular the 'Style output' and 'Row style output' templates. You must set the value attribute on the option to the url and will have to get javascript to listen to the onchange event and do the redirect. And you will most probably have to use the $row variable in the template, so remember to sanitize as it is print unsafe. Oct 29, 2014 at 13:30

3 Answers 3

3

Sure this is all possible:

  1. If you just want a select list assure you have the Ctools module installed on your site and use the Jump Menu views style output for your Partners content type. Alternatively use the Jump Menu module which you may find more helpful.

  2. Want this embedded into a block you say? Use the Views Field View module to place your output of (1) into a second view that is a block. If you go this route you likely want to enable caching in your Views.

Be sure to see the project page(s) for these modules.

0

That is very conditionnal, select is mean to be into a form element... If you wanted a block without a form, then a custom block would definitly be the best flexible solution as @j_reynolds suggest.

Anyway in views, you can create "form". When creating a page, just expose one of your filter criteria to user. And magic it create a form. It more look like a search page, not really what you asked.

But maybe you could consider to create a view that list all the teaser of your partner and add exposed filter on the name/title ?

0

For Drupal 8 or Drupal 9, you can create a view (block for example) that lists the titles of your content. Then, if the machine name of your view is my_view, you can create a twig template views-view-list--my-view.html.twig in which you include a dropdown.

Example with Bootstrap 4 dropdown (or you can use your own markup):

<div class="dropdown">
    <a class="btn dropdown-toggle" href="#" role="button" id="dropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
        Lorem
    </a>

    <div class="dropdown-menu" aria-labelledby="dropdownMenuLink">
        {% for row in rows %}
            <a class="dropdown-item" href="#">{{ row.content }}</a>
        {% endfor %}
    </div>
</div>

Your Answer

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

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