Closed (fixed)
Project:
Table of Contents
Version:
6.x-3.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Reporter:
Created:
3 Nov 2008 at 20:42 UTC
Updated:
4 Nov 2009 at 10:23 UTC
Is it possible to have the
render through a contemplate or a .tpl.php template file.
I need to have the table of contents show on every page of a specific content type, without requiring the user to add the code as they publish the page.
thanks in advance to any response
Comments
Comment #1
deviantintegral commentedWell, right now this is all through the input filter system. It could be done with hook_nodeapi where if the content type matches, it passes $node->body through the input filter manually. Doing it through a contemplate or template file probably won't work well, because the results won't be cached.
Another way (probably even better) would be to add a list of content types to the filter settings page (in the unstable version) where if selected, would add the table at the top regardless of the presence of a tag.
You might also be able to implement this yourself without any module changes. In your node-type.tpl.php file, try something like the following:
Though that's not really a clean solution. It would cause issues on larger sites as the filter wouldn't be cached.
Let me know how this goes; if we don't find an easy solution without modifying the module code, we can see about writing something for the 2.4 release.
--Andrew
Comment #2
Architeck commentedHey Andrew, Thanks for your help,
I tried the snippet of code your provided added to node-type.tpl.php file, made some changes and got it to work.
Here is the modified code.
thanks again, hope this helps anyone else trying to achieve the same functionality.
It would be nice to have an option to automatically tag the tableofcontents onto specific content types.
For now this may be something to add into the readme documentation.
Comment #3
willdashwood commentedI'd second that, although the above hack works it would be very useful to be able to automatically insert the TOC based on content type.
Comment #4
ellanylea commentedHaving the TOC automatically appear if any h2 exists on the page is a very helpful feature. By using the code in #2, the page execution time doubles, which is detrimental to a large site.
Before code in #2 used:
Page execution time was 299.87 ms.
Page execution time was 327.9 ms.
After code in #2 used:
Page execution time was 636.62 ms.
Page execution time was 603.59 ms.
Will you guide me and help me narrow down which function I should patch so that the TOC table shows up regardless of the presence of a tag? Then I'll be able to write a patch to help display TOC by content type.
Thanks!
Comment #5
freddyseubert commentedsubscribing
Comment #6
hatsch commentedsubscribing
Comment #7
nirvanajyothi commentedThis feature will be helpful. Subscribing.
Comment #8
AlexisWilke commentedThis feature will be integrated in the TOC filter. And hopefully the speed will be improved, but no guarantee there. 8-)
Comment #9
AlexisWilke commentedI added a drop down in the settings of the filter so people can get an automatic TOC in 3.x-dev.
It cannot be made specific to a node type (unfortunately) because it is a filter and filters may be applied to anything even non-node data. (i.e. blocks)
If you want to make it specific to a node type, use this module: http://drupal.org/project/filterbynodetype and assign only filters that make use of the automatic TOC on the corresponding node type.
Thank you.
Alexis Wilke
Comment #11
giorgio79 commentedThanks Alexis.
Just to confirm, with the new release, any H2 and H3 tags on a page are included in the TOC? I have several that are in contempalte but not inside the node body.
Comment #12
AlexisWilke commentedgiorgio79,
No, if it is only defined in your template, then it won't be found by the TOC module. The TOC module is a filter that works on the BODY of the node. Nothing else.
Thank you.
Alexis Wilke
Comment #13
giorgio79 commentedThanks Alexis, appreciate you taking your time and responding.
Would you have any tips or ideas that I can explore or write a patch regarding how to make this work with contemplate.
As I understand, instead of the node body variable, the module could be looking at the entire contemplate output as a variable and scan it for H2 and H3 tags. :)
Do you think this would be a big hack, and in turn would you accept such a patch if I make one?
Cheers,
G
Comment #14
AlexisWilke commentedWell... it isn't really clear. Is the ConTemplate using a filter to generate the final output? If so, you just have to put the TOC filter after the contemplate filter.
Reading their info, it did not feel like that was going to work. It seems that the way it works is by using a template.php file which means they get data that has already been filtered.
The will eventually be a problem since you could end up filtering multiple times (which does not work properly in many situations.)
I generally accept patches as long as they don't require Drupal Core changes that are not bugs. 8-)
Alexis
Comment #15
AlexisWilke commentedAh! Thinking about it, you may be able in your PHP code handling your contemplate to call a function in tableofcontents_...() to get it filtered for a TOC. That should be enough...
Comment #16
giorgio79 commentedThanks Alexis, I am starting to see the light.
Now I just need to find out what variable holds the contemplate output.
Gathering more info over here:
#617488: Make Contemplate work with Table of Contents
Comment #17
giorgio79 commentedAh I think I will just go with #1 and #2 :) That seems the simplest hack for the node template file, and get the TOC working for the entire $node->content :)