Closed (fixed)
Project:
Chaos Tool Suite (ctools)
Version:
7.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
6 May 2011 at 10:48 UTC
Updated:
10 Sep 2012 at 03:02 UTC
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
Comment #1
merlinofchaos commentedCTools 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).
Comment #2
mwonch commentedI 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.
Comment #3
merlinofchaos commentedWell, 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.
Comment #4
mwonch commentedOh, 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).
Comment #5
merlinofchaos commentedIn PHP, what you want is this code:
Depending on the context you may print the output or not.
That TRUE will default to collapsed, which I think is what you want.
Comment #6
mwonch commentedYou, sir, are awesome. Thank you!
Comment #8
Blu916 commentedHello, 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.
Comment #9
merlinofchaos commentedComment #10
Nikdilis commentedJust tested with Drupal 7.5 and Chaos 7.x-1.0-rc1:
the result:
Q
Q (collapsible)
What's wrong?
Comment #11
Nikdilis commentedSee #10 - Can anyone reproduce? Setting Status to active.
Comment #12
merlinofchaos commentedtheme() works differently in Drupal 7 than Drupal 6.
in D7 it needs to be print theme('ctools_collapsible', array('handle' => $question, 'content' => $answer));
Comment #13
Nikdilis commentedWorks! Thank you. Setting status to closed (fixed).
Comment #14
mrpauldriver commentedI 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.
Comment #15
nodecode commented@ Paul Driver
Try the following...
Comment #16
mrpauldriver commentedgreat thank you
Comment #17
merlinofchaos commentedComment #19
nitinmohan87 commentedI 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
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?
Comment #20
Lloyd commentedDisregard
Comment #21
bianchi commentedHi Guys,
From this variable :
How can I displays one panel at a time for this function ?
Thanks