0

I have an RSS feed for each user provided by the Views RSS module. The view uses

users/$uid/feed

as the display path. The feed is titled "All articles by 34 on example.com". The "34" is the userid being viewed. I want the title to be "All articles by username on example.com". I can't set this to use a variable/data in the views title field, which does change the RSS title.

  • I can't use hook_preprocess_html() or _page(), as these are not called for feeds
  • I don't see a hook in the Views RSS module, but I may have missed something
  • I don't want to do this in the theme templates for display, as this feels like the wrong place to put the logic

How do I change this? Is there another preprocess function I can use?

2

Not sure how much this will help as its not exactly what you're asking (i think):

I was using views_rss to show comment threads to a question_answer module question. But I wanted the question to show up as the 1st time in the RSS feed (as RSS feeds) may only show 1 piece of data by their nature (eg, comments or new posts or blog posts) ...

I didn't muck with the title of the Feed because I saw issues with Firefox Sage vs. Google Reader as what the "title" of the RSS feed is -- so I stuffed the "FAQ question" to the comment thread at the top of the RSS feed ....

/**
 * Implementation of hook_views_pre_render().
 *
 * For the comment rss feed we want the description to contain something such
 * as "topic #N: topic text". These values are excluded in the view already.
 * The RSS feed supports a description field but cannot have PHP code in it,
 * it's just static text.
 *
 * This is a means to theme the RSS description field for valid RSS feeds. The
 * view enforces that the parent node is published, and that comments are
 * published as well.
 *
 * http://stackoverflow.com/questions/4011505/how-can-i-add-a-summary-row-to-a-drupal-view
 */
function MYMODULE_discussion_views_pre_render(&$view) {

  if ($view->name == 'MYVIEW_discussion_comment_rss' &&
        $view->current_display == 'feed_1') {
    # Insert the question as a leading comment for this feed.
    $question = node_load(array('nid' => ARG(3)));
    $qrow = new stdClass();
    $qrow->comments_subject = htmlentities('Question Was:');
    $qrow->comments_comment = htmlentities($question->field_topic_text[0]['value']);
    array_unshift($view->result, $qrow);
  }
}

EDIT: My answer was coded for a D6 site, but the exact same principal applies to D7 (and I think the code as well).

1

Many thanks to the answer from @tenken which led me to the answer. After parsing the depth of the views array in his hook, I found where I could set the title:

function mymodue_views_pre_render(&$view) {
  if($view->name == 'user_rss' && arg(0) == 'users' && is_numeric(arg(1))) {
    $account = user_load(arg(1));
    $view->build_info['title'] = t('All articles by !username on Example.com', array(
      '!username' => $account->name,
    ));
  }
}
0

Maybe you can use this:

/**
 * Implements template_preprocess_views_view_rss().
 */
function module_preprocess_views_view_rss(&$vars) {
  if ($vars['view']->name == 'view_machine_name') {
    $vars['title']       = $new_title;  
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.