开发者

How do you modify the fields output in Drupal's RSS Feeds

开发者 https://www.devze.com 2022-12-15 17:47 出处:网络
Trying to modify the RSS feeds created by Views module in Drupal. Since there are no \'theme_\' hooks for the RSS feeds (rightfully as XML is theme-less), I need an alternate way to modify the field

Trying to modify the RSS feeds created by Views module in Drupal.

Since there are no 'theme_' hooks for the RSS feeds (rightfully as XML is theme-less), I need an alternate way to modify the fields that are output int开发者_如何转开发o the RSS, preferably using template.php if possible.

http://api.drupal.org/api/function/format_rss_item/6 looks promising as that is where each row is created, but it doesn't

node_feed() is what collects the nodes, creates the additional fields, and then calls format_rss_item().

Specifically, we need to remove the dc:creator element from the $extra array created in node_feed()


If you go into a specific content type, you can set the RSS display fields as per this post:

http://redfinsolutions.com/redfin-blog/show-hide-fields-views-generated-drupal-rss-feed


I am adding another answer, as I have recently had to do this and managed to do it without modifying data in the theme layer.

You can add a preprocess function to your view. It is a bit of work though.

There are some guidelines here, but they are a bit confusing. Here is my summary of how to do this.

First make sure your modules weight is > views

Secondly copy the template you would like to add a preprocessor to to your modules directory. Rename it to be something in the list of templates in theming information.

Then edit hook theme like this (but change to use the existing view that you need to override.

function mymodule_theme($existing, $type, $theme, $path) {
  // Copy the exsisting views theme from the existing array.
  $override = $existing['views_view_row_rss'];
  // Add my preprocessor to the list of preprocess functions
  $override['preprocess functions'][] = 'mymodule_myfunction';
  // Point to a template so that this view will be used.
  $override['template'] = 'my_more_specific_template_name';
  $override['path'] = drupal_get_path('module', 'path');
  unset($override['file']);
  // Return your theme handler.
  return array('my_more_specific_template_name' => $override);
}

You should then be able to write your preprocess code in the function mymodule_myfunction.


In the view, if you click on "style information" this will show you the template files used to create the feed. You can copy the template so that it is overridden for your view and remove dc:creator from the $item_elements array.

This is not particularly nice as you are modifying data in the theme layer, but it will do what you want.


I'd suggest using the Views Node Feed module to do this. It will let you completely write the XML that is output by Views for feeds.

0

精彩评论

暂无评论...
验证码 换一张
取 消