I've posted this to the forums and received no answers. The help pages for CTOOLS seem to be missing for this particular issue. So...

I'm new to CTOOLS and like the ability to use AJAX for things like collapsible text (FAQ pages in my case). However, I can't seem to figure out how to get it done. I already know how to input script calls into Drupal pages (after setting them to accept Full HTML), but I have no idea exactly what I have to do to collapse text for each FAQ entry.

If possible, could you provide sample code?

Comments

merlinofchaos’s picture

Status: Active » Fixed

CTools doesn't actually specifically have anything to do AJAX for collapsible text, so perhaps this is why the documentation is missing. It has a collapsible div tool but that just hides/displays the contents of a div when the arrow is clicked.

If you don't need the AJAX part, but just need the client-side javascript, see the documentation in includes/collapsible.theme.inc -- all that you have to do is this:

$output = theme('ctools_collapsible', $handle, $content, $collapsed).

 * @param $handle
 *   Text to put in the handle/title area of the div.
 * @param $content
 *   Text to put in the content area of the div, this is what will get
 *   collapsed
 * @param $collapsed = FALSE
 *   If true, this div will start out collapsed.
mwonch’s picture

I really appreciate this; thank you! Yours is the first answer I've received in a month.

However, I'm not proficient in code and not sure what I'm looking at or exactly what I'm supposed to do. May I trouble you to give a simple working example that I can copy, paste, and study? I promise not to just use the code itself. I'll actually work to understand it so I can do it later from a blank page, if needed.

merlinofchaos’s picture

Well, it's a code thing, so you'd have to embed it somewhere in your code. Maybe you should give me an idea of what you're trying to actually get collapsible before I give you an example; I'm afraid something I come up with won't actually be helpful and wouldn't be a good use of your time or mine without some better foundation of what you're trying to accomplish.

mwonch’s picture

Oh, very much appreciated! Again, thanks.

I'm building a FAQ/Q&A page. Actually, several of them for one site. It's basic, but I can't figure it out. I feel kinda stupid... I gather I'll need more of a basic understanding of PHP?

Anyway, all I want is a standard FAQ Q&A: click a linked question, the answer slides down; click again, it disappears. I'll be doing this page by page (article by article), so it'll have to work by pasting the code into the text areas configured to allow Full HTML. I have that part figured out, at least. LOL

If this can be done without calling a javascript file, that'd be optimal. If you know of page(s) that would provide a great example for me to follow, just linking to them will do. I'd just need to know which lines/commands pertain to what I'm trying to learn.

Now I know why coders are paid so well (or they should be, if not).

merlinofchaos’s picture

In PHP, what you want is this code:

$output = theme('ctools_collapsible', $question, $answer, TRUE);

Depending on the context you may print the output or not.

That TRUE will default to collapsed, which I think is what you want.

mwonch’s picture

You, sir, are awesome. Thank you!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Blu916’s picture

Version: 7.x-1.0-alpha4 » 7.x-1.x-dev
Status: Closed (fixed) » Needs review
Issue tags: +Chaos Tools

Hello, i've read through this thread multiple times, and i'm still having trouble getting this to work, if i could please get any help i would greatly appreciate it.

I enabled the Chaos Tools AJAX Demo page and it shows a collapsible div, which is what i would like to add to my articles and Basic Pages through CKeditor. I've enabled PHP in the CKeditor and have tried multiple different PHP codes, and code snippets and nothing seems to work. All i need it what is shown on the AJAX Demo Collapsible Div section and need to be able to place it in CKeditor, is this possible?

I've tried using theme_ctools_collapsible, pulling the PHP directly from ctools_ajax_sample_page, and i've also tried using collapsible.theme.inc.

I would greatly appreciate any and all help, thank you.

merlinofchaos’s picture

Status: Needs review » Closed (fixed)
Issue tags: -Chaos Tools

Issue tags: +Chaos Tools

Please read the issue tag guidelines before adding random issue tags. The link is right there by the widget.

Status: closed (fixed) » needs review

Same for issue status guidelines.

I'm unable to answer questions about CKEditor, so there's nothing I can add there. In terms of using this tool, the code you need is in #5. There's really not much more I can add.

If the ajax sample module does what you want, you can look at the code there and try to adapt it to your needs.

Nikdilis’s picture

Just tested with Drupal 7.5 and Chaos 7.x-1.0-rc1:

$question = 'Question?';
$answer = 'Answer!';

$output = theme('ctools_collapsible', $question, $answer, TRUE);
print $output;

the result:
Q
Q (collapsible)

What's wrong?

Nikdilis’s picture

Status: Closed (fixed) » Active

See #10 - Can anyone reproduce? Setting Status to active.

merlinofchaos’s picture

theme() works differently in Drupal 7 than Drupal 6.

in D7 it needs to be print theme('ctools_collapsible', array('handle' => $question, 'content' => $answer));

Nikdilis’s picture

Status: Active » Closed (fixed)

Works! Thank you. Setting status to closed (fixed).

mrpauldriver’s picture

Status: Closed (fixed) » Active

I am new to ctools and php but want to achieve something similar.

I my case the content that I wish to reveal is a google docs embedded image. I have managed to get the code working, but the default state based on the code below is with the content explanded.

What do I need to change for the default state to be collapsed?

Any help much appreciated.

<?php  
$viewimage= 'View Image';  
$image= '<img src="https://docs.google.com/drawings/pub?id=1SolYgwkjiexJ0LogqmkET1CutALV4RD2WwlFKOS3_Jc&amp;w=940&amp;h=600">';  $output = theme('ctools_collapsible', array('handle' => $viewimage, 'content' => $image)); 
print $output; 
?>
nodecode’s picture

@ Paul Driver
Try the following...

$viewimage= 'View Image'; 
$image= '<img src="https://docs.google.com/drawings/pub?id=1SolYgwkjiexJ0LogqmkET1CutALV4RD2WwlFKOS3_Jc&amp;w=940&amp;h=600">';  
$collapsed = TRUE;
$output = theme('ctools_collapsible', array('handle' => $viewimage, 'content' => $image, 'collapsed' => $collapsed));
print $output;
mrpauldriver’s picture

great thank you

merlinofchaos’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

nitinmohan87’s picture

I am trying to post a bunch of FAQ questions using the ctools collapsible div. Each question will be the handle and the answer will be its content.

So, I code it like this

$question = 'Question 1';
$answer = 'Answer 1';
print theme('ctools_collapsible', array('handle' => $question, 'content' => $answer, 'collapsed' => TRUE));

$question = 'Question 2';
$answer = 'Answer 2';
print theme('ctools_collapsible', array('handle' => $question, 'content' => $answer, 'collapsed' => TRUE));

But my output is like this
Question 1
>>>>Question 2

When collapsed
Question 1
Answer 1
>>>>Question 2
>>>>Answer 2

Expected output
Question 1
Answer 1
Question 2
Answer 2

How to bring the rest of the questions in the same margin as Question 1 using ctools collapsible divs?

Lloyd’s picture

Disregard

bianchi’s picture

Hi Guys,
From this variable :

$output = theme('ctools_collapsible', $question, $answer, TRUE);

How can I displays one panel at a time for this function ?
Thanks