I'm trying to theme the output of the node which gets loaded inside the gmap popup and have found http://drupal.org/node/130671">instructions for theming gmap popups for NON-views pages, but unfortunately can't seem to find anything about theming gmap popups on views-generated pages.

Any suggestions will be much appreciated.

CommentFileSizeAuthor
#1 gmap_views_themable_markers.patch1.21 KBbensheldon

Comments

bensheldon’s picture

Title: How to theme gmap popups when used with a view? » Patch to add themeable markers
Category: support » feature
Status: Active » Needs work
StatusFileSize
new1.21 KB

Here is a patch for gmap_views.module that simply takes the current code that generates marker windows for Views and passes it through a hook_theme function. This allows the marker windows theme to be overridden by traditional methods.

The default marker theme code is this:

/**
 * Theme a marker label.
 */
function theme_gmap_views_marker_label($view, $fields, $entry) {
  $marker_label = '';
  foreach ($view->field as $field) {
    $marker_label .= '<div class="'. $field['field'] .'">'. views_theme_field('views_handle_field', $field['queryname'], $fields, $field, $entry, $view) .'</div>';
  }
  return $marker_label;
}
Caleb G2’s picture

Status: Needs work » Reviewed & tested by the community

This is a great patch. Thanks bensheldon. Marking rtbc. Once I have fleshed out my tpl file a little more I'll come back and paste the code and/or attach the files to help the next person along.

Caleb G2’s picture

So using this patch it boils down to:

1. patching gmap_views.module

2. Adding this to template.php:

/**
 * Theme a gmap marker label.
 */
function phptemplate_gmap_views_marker_label($view, $fields, $entry) {
return _phptemplate_callback('gmap_views_maker_label', array('view' => $view, 'fields' =>
$fields, 'entry' => $entry));
}

3. Creating a file called gmap_views_maker_label.tpl.php and adding:

<?php
  $marker_label = '';
  foreach ($view->field as $field) {
    $marker_label .= '<div class="gmapstyle-'. $field['field'] .'">'. views_theme_field('views_handle_field', $field['queryname'], $fields, $field, $entry, $view) .'</div>';
  }
  print $marker_label; ?>

4. Note the added 'gmapstyle-' which is added to the class in order to make it easier to find in the mess of code that gets generated by all of this. Fine tuning of themeing can involve a) editing css, b) editing the tpl file itself, and/or c) creating new versions of the gmap views and editing the fields and/or the order of the fields.

bdragon’s picture

Status: Reviewed & tested by the community » Fixed

Congratulations, you win the "closest to something I had locally but forgot to commit" prize!

You had better commentation and a function name, so I just adapted mine to pretty much match yours.

*committed*

Thanks!

--Brandon

dries’s picture

Status: Fixed » Closed (fixed)
njehlen’s picture

I was able to theme views in general using this code - can someone give an example of how to theme different views differently?

thomasmuirhead’s picture

I was having trouble with this for a while so just in case anyone was too check that you are spelling marker with an 'r' wherever you use it... as above the 'r' seems to have been dropped in some cases and not in others.

I changed them all to having the r and everything worked...thanks for the solution guys it's made using gmap views a possibility.

Thomas