2

I'm currently using the Calendar module in Drupal 7 and wish to add a wrapper with a class around the entries on days that have entries.

I've attempted to do this in the various template files and have been testing variables available with print_r for the last hour or so.

The a quick print_r in calendar-month-col.tpl.php provides the following arrays, either an empty day:

Array
(
    [entry] => <div class="month day"> 2 </div>
    [colspan] => 1
    [rowspan] => 1
    [class] => date-box future empty
    [date] => 2015-05-02
    [id] => events-2015-05-02-date-box
    [header_id] => Saturday
    [day_of_month] => 2
)

or a day with an event:

Array
(
    [entry] => <div class="item">
  <div class="view-item view-item-events">
  <div class="calendar monthview">
        <div class="calendar.1.field_date_time.0.0 contents">

          <a href="/node/1/edit?destination=node/6">edit</a>    
          <a href="/residents/events/test-event">Test Event</a>            </div>  
        <div class="cutoff">&nbsp;</div>
      </div> 
  </div>   
</div><div class="item">
  <div class="view-item view-item-events">
  <div class="calendar monthview">
        <div class="calendar.42.field_date_time.0.0 contents">

          <a href="/node/42/edit?destination=node/6">edit</a>    
          <a href="/residents/events/test-event-2">Test Event 2</a>            </div>  
        <div class="cutoff">&nbsp;</div>
      </div> 
  </div>   
</div>
    [colspan] => 1
    [rowspan] => 1
    [class] => single-day future
    [date] => 2015-04-30
    [id] => events-2015-04-30-0
    [header_id] => Thursday
    [day_of_month] => 30
)

I've considered checking for an existing string (empty days have the class "empty" or "no-entry")

Any suggestions?

Edit: For the time being, I've put a quick solution together that will let me style the Calendar as needed.

$strings = array('empty','no-entry');
foreach($strings as $string):
  if (strpos($item['class'],$string)!==false):
    $addstring = "";
    break;
    else :
    $addstring = "event ";
  endif;
endforeach;

It's not nearly as clean as I would like, but it works.

Edit: Added !== false to strpos.

As a side note, I ended up simply css'ing out the date-box row.

  • Welcome to Drupal Answers! In order to get help, you should add more context to your question, e.g. which module you are referring to, what have you tried already and how did that fail. See How do I ask a good question? for more information. – berliner Apr 29 '15 at 0:07
  • Fair enough; in short, I'm using the calendar module and I'd like to add a wrapper (div) with a class around entries using the calendar-month-col.tpl.php. Insofar as what I've tried, I've been spitting print_r variables and noted that there's nothing specific to target with an if statement. – Dooley Apr 29 '15 at 0:08
  • Don't refrain from posting code snippets. I won't be able to help because I don't know the module. But the more info you give, the higher the chances that someone else can help you. Good luck! – berliner Apr 29 '15 at 0:12
  • I've edited the question to provide more detail. I don't think there's much more pertinent information to include, but if you need anything else, let me know. – Dooley Apr 29 '15 at 0:15

Your Answer

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

Browse other questions tagged or ask your own question.