2

enter image description here

For example, how can I show Jul 4 (Mon) instead of the default Mon as day title?

3 Answers 3

2

Y rectify like this and that seems good for me:

function template_preprocess_calendar_week(&$vars) {
$min_date = clone $vars['view']->date_info->min_date;
foreach ($vars['day_names'] as &$cell) {
 $cell['date'] = $min_date->format('j');
 $cell['data'] = $cell['data'] . ", " . $cell['date'];
 $min_date = $min_date->modify('+1 day');
}
}
1

You need to add your own theme template for your calendar month display.

Within the Views UI under the Advanced > Theme: Information link you'll find a link to display the template for calendar-month.tpl.php. You can copy the template over to your theme's template directory. After flush the cache, you can start using that copy as your own custom calendar month template.

Within the template you can see where the header is added via iteration over the $day_names variable.

<div class="calendar-calendar"><div class="month-view">
<table class="full">
  <thead>
    <tr>
      <?php foreach ($day_names as $id => $cell): ?>
        <th class="<?php print $cell['class']; ?>" id="<?php print $cell['header_id'] ?>">
          !!!<?php print $cell['data']; ?>
        </th>
      <?php endforeach; ?>

You can alter it accordingly.

Alternatively, if you prefer to just alter the templates variables. You can add your own theme function for template_preprocess_calendar_month() in your theme's template.php. For example:

function mytheme_preprocess_calendar_month(&$vars) {
  // @TODO: Alter $vars['day_names'] to adjust day headers
}
2
  • I traced to function calendar_week_header($view) in calendar.module and found the title text are built from calendar_untranslated_days which contains only weekday names (i.e. "Mon", "Tue", .. etc.), it seems the actual day info (e.g. 4th) is not there.
    – ohho
    Commented Jul 8, 2016 at 8:35
  • Your need (adding a day context) is different from the template's design (a generic label that describes each day in the column). You'll need to add your own logic to determine the day context.
    – Shawn Conn
    Commented Jul 8, 2016 at 8:45
1

Thanks to Shawn Conn's tips, here is how I modify the $day_names:

function template_preprocess_calendar_week(&$vars) {

  ...

  $min_date = clone $vars['view']->date_info->min_date;
  foreach ($day_names as &$cell) {
    $cell['date'] = $min_date->format('M j');
    $cell['data'] = $cell['data'] . ", " . $cell['date'];
    $min_date = $min_date->modify('+1 day');
  }

  ...
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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