I have multiple KML views and for each one I need to output additional fields using a custom kml-placemark.tpl.php file. As far as I can tell I can't do this.

I've tried putting the template into my theme but Views won't recognize it.

template_preprocess_kml_placemark() doesn't seem to have a way to differentiate between my different views.

Am I missing something simple or does extra functionality need to be added to kml.module?

Comments

jeffschuler’s picture

StatusFileSize
new1.63 KB

Sounds to me like two different questions here. Please correct me if I'm wrong.

I'm hearing, first of all, that a kml-placemark.tpl.php template file file in your theme is not working at all...? I just double-checked this with 6.x-2.x-dev and had no issues. (I put a copy of kml-placemark.tpl.php into my theme directory (actually just tried with the Sky theme, so I put it in templates/overrides,) edited it, cleared the cache and saw the changes in my views-exported KML.)

And secondly, that you want a different template for each view.

Check out the attached patch. I'm passing $view into template_preprocess_kml_placemark(). You can then make decisions there based on ->current_display or whatever.

I'm not sure if-and-how I'd want to incorporate this into the module, but you should be able to re-implement template_preprocess_views_view_kml() and template_preprocess_kml_placemark().

Does that get you far enough?

langworthy’s picture

Ok. First problem solved. I'm not sure what I was doing wrong before but I'm able to drop kml-placemark.tpl.php into my theme and it gets picked up.

As for my second issue, let me clarify what my goal is. I need to add <ExtendedData> and <Data> elements to the KML that is populated by the extra fields in the view.

I'm thinking I need to add a checkbox to the options form asking if extra fields should be in <ExtendedData> and a row style plugin that prints out labels and values properly. Right now I don't seem to have enough data in $vars['content'].

jeffschuler’s picture

You don't have those additional fields each as $vars['content'][$field_key]?

You're using 6.x-2.x-dev, right? Seen the changes that went in via #1252348: Make remaining fields available in point?

langworthy’s picture

I have the field values but not the labels. Is there an easy way to get the labels?

jeffschuler’s picture

What if we did something like this?

langworthy’s picture

#5 is exactly what I need for getting the label into my custom theme. I followed that up with a new issue at #1623342: Add 'label' to $vars['content'] for theming

Now I'll see about the patch in #1 for multiple views.

Thanks so much for the help Jeff.

jeffschuler’s picture

Title: How to use additional fields? » Change placemark template per view
Status: Active » Needs review

Cool. Changing issue title to reflect re-focus.
Patch in #1 needs review.

langworthy’s picture

Status: Needs review » Needs work

The patch in #1 would result in a single template file with conditional logic checking the view name. I think the "Drupal way" is to suggest template name patters and allow for a template file per view (or display). The template file in use should appear in "Theme: Information" when editing a view. I don't currently see this.

What is the simplest way to allow for template name suggestions and a template per view or display?

jeffschuler’s picture

That's a way better idea. :)

langworthy’s picture

Status: Needs work » Needs review
StatusFileSize
new15.47 KB

- I got this working on an installation of kml.module that is running #934482: WKT support. I made the changes to 2.x-dev by hand. I hope I didn't miss anything.
- The options have been moved from the style plugin to the row plugin.
- I made a few small coding standards changes (whitespace and line endings) where it affected changed code. I see more that needs attention but that should probably be in another patch.
- I don't see an option for linestring so for now I've removed it from map_row() (function name used to be map_rows()

langworthy’s picture

StatusFileSize
new15.47 KB

- Removing #934482: WKT support specific code

langworthy’s picture

Note: the patch in #11 will fail using the patch command. It will work when using git apply.

Here's why:

#renamed:    views/views_plugin_style_kml.inc -> views/views_plugin_row_kml.inc
#modified:   views/views_plugin_style_kml.inc

Git moves a file and then modifies it. git apply is smart enough to figure this out. patch is not.

I also noticed that the patch failed on the 6.x-2.x-dev release download. It works on a git checkout of the 6.x-2.x branch.

langworthy’s picture

Component: Documentation » Code
Category: support » feature