We help IT Professionals succeed at work.
Get Started

Preprocess function to modify title

bogorman asked
Last Modified: 2012-06-21
I have created a view (called magazine_articles) which generates a list of titles and authors (based on a content type called Article).
When I group the fields by IssueDate, the block appears thus:

Jan 2010
Title        Author
Title        Author

Nov 2009
Title       Author


The articles are in a bimonthly magazine which is published on our website.
What I want to do is to convert the group headings to:

Jan-Feb 2010
Nov-Dec 2010
Sep-Oct 2010

I have tried to write a preprocess function in my template.php file (in my theme directory):

function faith_home_preprocess_views_view__magazine_articles(&$variables) {
  $month = substr($variables['title'],0,3);
  $year = substr($variables['title'],4,4);
    case "Jan": $issuename="Jan-Feb"; break;
    case "Mar": $issuename="Mar-Apl"; break;
    case "May": $issuename="May-Jun"; break;
    case "Jul": $issuename="Jul-Aug"; break;
    case "Sep": $issuename="Sep-Oct"; break;
    case "Nov": $issuename="Nov-Dec"; break;
    default: $issuename = "None"; break;
$title = $issuename." ".$year;
  $variables['magtitle'] = $title;


I have modified the coding in my views-view-table--magazine_articles.tpl.php file to:

<?php if (!empty($magtitle)): ?>
  <<?php print $group_element; ?><?php print drupal_attributes($group_attributes); ?>>
    <?php print $magtitle; ?>
  </<?php print $group_element; ?>>

but no group headings are printed.

Can anyone tell me how I can solve this?
Watch Question
This problem has been solved!
Unlock 1 Answer and 23 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE