I'm trying to create a button that create a new content type based on the one selected in the view filter. I have had some problems finding the correct variables to use them in that case. I'm actually new in the drupal community (so don't be mean if my question is irrelevant for you).

Edit: The code is the one provided as an example for the view with seven as a theme. The part i want to edit is this one :

  **<?php if ($exposed): ?>
    <div class="view-filters">
      <?php print $exposed; ?>
       * Création d'un bouton de rajout de proposition (yes, this is french ^^)
         $chemin = "../node/add"; // i want this URL to be dynamic and to change each time           
         //someone clic on a new option in the exposed filter. E.G. if he clics on volvo,     the 
         //button should show "add a new volvo car" with the proper link
    print"<a href=\"".$chemin."\">
    <input type=\"submit\" class=\"button\" name=\"Ajout Type de Contenu\" value=\"Ajouter     une XXX\" /> 
    </a>" ; 
  <?php endif; ?>**

Thanks !

  • Not sure what you have tried so far. The right Views hook should have the variables you need. If you don't have the Devel module, install it and you can use dpm to dump the vars and track down the ones you need. If you have already done this please go in to more detail about what you have tried.
    – sareed
    Apr 13, 2015 at 17:25
  • Welcome to Drupal Answers :) No one's going to be mean to you (this is the internet after all!), but as this is a Q+A site, we are going to need you to ask a specific question. Sounds like that should be pretty easy for you to do, just edit the question and provide the code you're using, and a brief description of what variables you can't find
    – Clive
    Apr 13, 2015 at 17:30
  • @Clive : It's done, the code is part of the "views-view--propositions.tpl.php" template file given as an example by drupal. Sareed I tried dpm but I didn't find the proper variables to do this :( (Thought that i was close by exploring $filter)
    – Ismail H
    Apr 14, 2015 at 7:27
  • Just to clarify, are you using filters or contextual filters?
    – rooby
    Apr 14, 2015 at 8:30
  • @rooby I'm using filters (on taxonomy terms)
    – Ismail H
    Apr 14, 2015 at 8:43

1 Answer 1


If I understand correctly your current problem is getting the current values of the exposed filters.

Wherever you are putting your code, as long as you have access to the view object you can get these values using view::get_exposed_input() like this:

$filters = $view->get_exposed_input();
// You can then access the value of a specific filter like this.
$value = $filters['FILTER_NAME'];

You can then use those values to implement whatever logic you require.

  • Yes ! Thank to @rooby, i did manage to solve the problem. I used Drupal's function taxnomy_term_load $filters = $view->get_exposed_input(); $term_filter = taxonomy_term_load($filters['term_node_tid_depth_1']); $value = $term_filter->name; // and here is the name. Thank you all
    – Ismail H
    Apr 14, 2015 at 11:51
  • Nice one. Note that term names are input by users so it is a potential cross site scripting security issue to just print term name to the markup. Best to use check_plain() or similar before printing.
    – rooby
    Apr 14, 2015 at 12:01

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.