1. (my requirement) when wanting to control the content of the view title for a listing of locations (E.g. title "venues near you") created using a view with Drupal module ip_geoloc ("IP Geolocation Views & Maps") based on the user's detected location (via html5 geo location) and then offering further searches (e.g. a different specific location) and wanting to display a different title in those results "venues near New York City"

  2. simpler example "search again" for subsequent displays of the form (an user-visible views exposed filter).

For example 1., I'm currently using hook_views_pre_render in my own custom module to compare the submitted value with the detected location to be able to set a custom title for the view, snippets (note, not full declaration and module) of how I get each of these here:

    $locationAsString = "";

    if (function_exists('ip_geoloc_get_visitor_location') ) { 
      $locationAsArray = ip_geoloc_get_visitor_location(); 

      // debug

      if ( isset($locationAsArray['locality']) ) {
        $locationAsString = t($locationAsArray['locality'].", ".$locationAsArray['country']);

    $submittedLocationAsString = "";
    if ( isset($view->exposed_raw_input['field_geofield_distance']['origin'] ) )
       $submittedLocationAsString = $view->exposed_raw_input['field_geofield_distance']['origin'];

    // debug:
    //drupal_set_message( "submitted location is: ".$submittedLocationAsString );
    //drupal_set_message( "actuallocation is: ".$locationAsString );

    if ( $locationAsString == $submittedLocationAsString )
      $view->build_info['title'] = "We think you're near ".$locationAsString.". ".$thereAreAsString." here.";
      $view->build_info['title'] = $resultsAsString." near ".$submittedLocationAsString;

My ideal solution

But as you can see, this straight compare is not necessarily that robust. To determine the title I want, I think it may actually be better to insert a hidden field in the form, in hook_form_alter and detect the value/presence of this field in cgformutils_views_pre_render - is this approach within convention and not 'illegal' or bad practice?


Though I am providing the solution for the question which you have asked but as per your description I understand you are looking to achieve content boosting with views.

It's a nice idea which has been implemented on some websites like meetup.com, where they boost the local event at top when you visit & these works for anonymous users too as well as authenticated.

You will need 3 modules to achieve this - Location, Smart IP & Views.

I have written a blog post about configuring them to achieve this, which you can find at - http://drupalconnect.in/content-boosting-views

I will recommend you to try this if you trying something like this :)

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.