I need to generate multiple XML outputs each with a separate View. The XML outputs follow several complex and verbose metadata format standards (FGDC, ISO 19139, DC) and I would like to have separate templates for them.

How can I have multiple views-views-xml-style-raw.tpl.php template files in my Theme folder?
Renaming the templates to views-views-xml-style--[view name].tpl.php or views-views-xml-style-raw--[view name].tpl.php gave me errors or were ignored.

Comments

wgrunberg’s picture

I am now using $view->name to identify the name of the View that is calling the template and use if statements to sort out my multiple template needs. I probably could create an include for each metadata standard to make it tidy.

allisterbeharry’s picture

Assigned: Unassigned » allisterbeharry
Status: Active » Fixed

Proper overriding of template files using the Views override mechanism is now available in the 6.x-1.0-beta1 release. For a view named [view name] placing a file
views-views-xml-style-raw--[view name].tpl.php in your current site theme directory will override the default output of the plugin. Have a look inside template_preprocess_views_views_xml_style_raw in views_views_xml_style.theme.inc to see how the XML is generated in the default case and adjust for each case you have.

wgrunberg’s picture

Thank you allisterbeharry!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

rickmanelius’s picture

Status: Closed (fixed) » Active

The instructions in #2 did not work for me. Here is what I did...

I have a view (called audios) and I want to override the output. If I copy views-views-xml-style-raw.tpl.php in the theme folder, I can definitely modify the output to a page. However, when I follow the advice and rename it to views-views-xml-style-raw--audios.tpl.php, it simply does not work because views ignores the tpl file altogether. I can try to echo out "hahahahahahahahahahahaha" and get nothing.... but it worked using views-views-xml-style-raw.tpl.php.

So I tried views-views-xml-style--audios.tpl.php, because that's what the views theme information window recommended. Interestingly enough I can get the "hhahahahaahhaa" text to echo out, but the $xml variable is not created and thus the actual information itself is not output.

In summary
A) views-views-xml-style-raw.tpl.php WORKS... but not specific to a view
B) views-views-xml-style-raw--audios.tpl.php DOES NOT WORK -- template file ignored.
C) views-views-xml-style--audios.tpl.php override called but no $xml created

My recommendation is to keep it in form C, but I understand that there are some code considerations that make B more preferable. But it seems to conflict with views... which recommends C even though this module wants to use B... but then the variable doesn't seem to be created.

This is not a huge issue for me at the moment, as I only need one view to use this override at the moment. But I have a feeling that it's going to become very important rather quickly as I make custom video and text RSS feeds...

Any advice/pointers on what to do would be very helpful. I'm somewhat skilled at php but not so much at the entire views architecture... so I'd be happy to help out if I can. But I don't know if I'm skilled enough to provide a patch that would not potentially conflict with other things this module is trying to do.

allisterbeharry’s picture

Version: 6.x-1.x-dev » 6.x-1.0-beta2
Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

oramirite’s picture

Hello - I have successfully themed a specific view, but I was also trying to theme some individual fields today and I'm running into the same issue of my theme files being ignored. They are recognized by Views just fine but don't actually affect the output.

I need to customize the XML tagging for two of my fields (to create two 'media' tags in an mRSS playlist) and this seems like the best way to do it. Are there any workarounds or patches to accomplish this?