2

I have some panels on my site. Previously, I was using custom content panes with the PHP filter to call functions in a custom module. The custom function had lots of print() statements and I simply dumped a bunch of HTML to the screen.

Now, I am trying to reform my bad programming practices by moving the custom content panes into Ctools content types. I successfully created a content type, but when I call my function (in my custom module) full of print() statements, all of the HTML gets dumped to the top of the page, instead of where the content type has been placed within the panel.

Reading through articles online, it appears this is because the content pane expects me to return something it can render, not directly print() the HTML. Is there another PHP function I can use to gather up all the HTML I was previously using print() for? What is the correct way to output a bunch of HTML in a ctools content type?

(If this seems obvious, please bear with me. I'm not a programmer by training and I'm probably in a bit over my head.)

2

From the top of my head you should simply be able to do:

$pane = new stdClass();
$pane->title = 'Check this out!'; // Optional
$pane->content = '<div>My content</div>';
return $pane;

It's also worthwhile to review What are Ctools plugin (content type, access, etc), and how does one create them? which contains an example content type.

The question Correct way to render a modules output through a template? shows an example of rendering through a template, so you can strip the markup out from your pane and have it contain only the relevant content.

  • Thanks! So I managed to get everything into content by changing every print() to dump it into a string ($output .= ABC) and then returning the string. – Patrick Kenny Nov 13 '14 at 13:20

Your Answer

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

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