How to make sure that panels classes are added to a CTools pane? I am attempting to define a CTools content pane based on the tutorial here.  However, when I add my pane to the panel, no matter what region (left sidebar, header, footer) I add it to, it is printed at the top of the page without any of the region or pane CSS classes.

This is the function I am using to render the pane:

function MYMODULE_messagelimits_content_type_render($subtype, $conf, $args, $context) {
  if (!empty($conf)) {
    $block = new stdClass();
    $block-&gt;title = check_plain("");
    // Show message limits
    $block-&gt;content = MYMODULE_show_message_limits();
    return $block;
  }
}


MYMODULE_show_message_limits() is a function that prints out some information to show users what their messaging limits are, for example:

if ($sent_total &gt; 1) {
  print '&lt;div class="messagesng"&gt;';
  print t('You have already started conversations with 2 people this week.') . '&lt;/div&gt;';    }
else if ($sent_total == 1) {
  print '&lt;div class="messagesok"&gt;' . t('You can start a conversation with 1 more new person this week.') . '&lt;/div&gt;';
}
else {
  print '&lt;div class="messagesok"&gt;' . t('You can start conversations with 2 new people this week.') . '&lt;/div&gt;';
}


If I make a change such as $block-&gt;content = t("my sample content"), then the pane is printed with the correct classes in the proper place on the page.

So how can I set the output of $block-content to be the output of my custom module's function while retaining the panels CSS classes?  Please help me stop abusing the PHP filter within Panels!
In the following function, the content is provided by t(). t(), when called, returns the text "my sample text". Because that text gets assigned to $block-&gt;content, the pane is rendered with "my sample text" as the content.

function MYMODULE_messagelimits_content_type_render($subtype, $conf, $args, $context) {
  if (!empty($conf)) {
    $block = new stdClass();
    $block-&gt;title = check_plain("");
    // Show message limits.
    $block-&gt;content = t("my sample content")
    return $block;
  }
}


By contrast, this function:

function MYMODULE_messagelimits_content_type_render($subtype, $conf, $args, $context) {
  if (!empty($conf)) {
    $block = new stdClass();
    $block-&gt;title = check_plain("");
    // Show message limits
    $block-&gt;content = MYMODULE_show_message_limits();
    return $block;
  }
}


Assigns the return value of MYMODULE_show_message_limits() to $block-&gt;content, rendering the pane with that function's return value. To understand why that doesn't work as expected, we must ask, what does MYMODULE_show_message_limits() return?

if ($sent_total &gt; 1) {
  print '&lt;div class="messagesng"&gt;';
  print t('You have already started conversations with 2 people this week.') . '&lt;/div&gt;';
}
else if ($sent_total == 1) {
  print '&lt;div class="messagesok"&gt;' . t('You can start a conversation with 1 more new person this week.') . '&lt;/div&gt;';
}
else {
  print '&lt;div class="messagesok"&gt;' . t('You can start conversations with 2 new people this week.') . '&lt;/div&gt;';
}


The function above, lacks a return statement, so in pratice, it returns NULL. Hence the pane output is empty, not even an empty string.

MYMODULE_show_message_limits() does, on the other hand, execute several print calls. Since that happens at a stage when content is still being assembled, remember, this is not a template, the prints are thrown right out onto the page, in the same way it would have if it was executed in any hook invocation for example.

The solution then, is to do:

$output = '';
if ($sent_total &gt; 1) {
  $output .= '&lt;div class="messagesng"&gt;';
  $output .= t('You have already started conversations with 2 people this week.') . '&lt;/div&gt;';
}
else if ($sent_total == 1) {
  $output .= '&lt;div class="messagesok"&gt;' . t('You can start a conversation with 1 more new person this week.') . '&lt;/div&gt;';
}
else {
  $output .= '&lt;div class="messagesok"&gt;' . t('You can start conversations with 2 new people this week.') . '&lt;/div&gt;';
}
return $output;