I want to add this link : resources?field_resources_type_tid_i18n[0]=130 in the main menu that point to a view with exposed filter. But When I save my link I just find resources without query parameter


There are multiple ways to solve this problem.

  1. Use the absolute URL of the page, instead of the Drupal path.
  2. Write a module that provides a menu item via hook_menu(), e.g. for the path resources/field_resources_type_tid_i18n/130. The page callback for the menu item would either redirect to resources?field_resources_type_tid_i18n[0]=130 or serve the desired page directly.

  3. Add a rewrite rule to the webserver configuration, the translates resources/field_resources_type_tid_i18n/130 into index.php?q=resources&field_resources_type_tid_i18n[0]=130 and add resources/field_resources_type_tid_i18n/130 to the menu.

Solution 1 is the most simple, but not very flexible. You need to touch the menu links database table if the absolute URL of the site changes. Adapting the link to the currently used scheme (http:// or https://) is not possible.

I prefer Solution 2, but it requires knowledge about Drupal module development.

I do not like to rely on URL rewriting to provide essential functionality, so I do not recommend Solution 3.


Case: you have an existing menu block in your structure. You can add query parameters to existing menu link paths by adding the query option. (see url())

function (your_module_name)_block_view_alter(&$data, $block) {
  if ($block->delta == "main-menu") {
    $data['content'][601]['#localized_options']['query'] = array('yourqueryparameter' => 'parameters value');

For more dynamic code:

... if ($block->delta == "main-menu") {
foreach ($data['content'] as $menu_link){
  if (isset($menu_link['#href']) && $menu_link['#href'] == "Link_of_your_menu_item" ){
    $data['content'][$menu_link['#original_link']['mlid']]['#localized_options']['query'] = array('yourqueryparameter' => 'parameters value');

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.