Search code examples
drupaldrupal-7drupal-modules

Why content appears misplaced?


I am building a custom module which should display a calendar created by a third-part library. So far, so good. The only problem is, the calendar appears on top of page, even above header. It does not seems to be css-related.

This is the way it looks: enter image description here

This is my module file:

require_once 'includes/apphp-calendar/calendar.class.php';

function calendario_menu(){

  $items = array();

  $items['eventos/calendario'] = array( 
    'title' => 'Calendario', 
    'description' => 'Calendario de Eventos.',
    'page callback' => '_page_calendario',
    'access callback' => TRUE,
    'type' => MENU_CALLBACK,
  );

  return $items;
}


function _page_calendario() {
  $objCalendar = new Calendar();
  $calendar = $objCalendar->Show();

  return array(
    '#markup' => $calendar
  );
}

Solution

  • Seems to me like the Show function of the calendar class outputs rather than returning a string.
    try this:

    function _page_calendario() {
      $objCalendar = new Calendar();
      ob_start();
      $objCalendar->Show();
      $calendar = ob_get_contents();
      ob_end_clean();
    
      return array(
        '#markup' => $calendar
      );
    }