Patch to add themeable markers

Caleb G2 - April 20, 2007 - 01:26
Project:GMap Module
Version:5.x-1.x-dev
Component:Documentation
Category:feature request
Priority:normal
Assigned:Unassigned
Status:closed
Description

I'm trying to theme the output of the node which gets loaded inside the gmap popup and have found 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.

#1

bensheldon - April 22, 2007 - 22:48
Title:How to theme gmap popups when used with a view?» Patch to add themeable markers
Category:support request» feature request
Status:active» needs work

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;
}

AttachmentSize
gmap_views_themable_markers.patch 1.21 KB

#2

Caleb G2 - April 25, 2007 - 23:19
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.

#3

Caleb G2 - April 26, 2007 - 21:31

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.

#4

bdragon - April 27, 2007 - 20:43
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

#5

Dries - May 14, 2007 - 20:42
Status:fixed» closed

#6

njehlen - September 21, 2007 - 02:31

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

#7

thomasmuirhead - December 9, 2008 - 18:09

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

 
 

Drupal is a registered trademark of Dries Buytaert.