Closed (fixed)
Project:
Table of Contents
Version:
6.x-3.x-dev
Component:
Code
Priority:
Normal
Category:
Support request
Assigned:
Reporter:
Created:
22 Sep 2009 at 14:51 UTC
Updated:
11 Oct 2009 at 01:40 UTC
Hi,
I need to call toc inside a tpl, using php.
How can i do this?
Which function should i use?
How?
So, i cant use:
i need something in php like:
$node = headinganchors_filter('process', null, null, $node);
$node = tableofcontents_filter('prepare', null, null, $node);
$node = tableofcontents_filter('process', null, null, $node);
but i'm not sure...
how can i achive this goal?
thanks,
Carlos
PS: the tpl is for a view, because i couldn't use it the html in header (it doesn't process)
Comments
Comment #1
AlexisWilke commentedHi Carlos,
If you still have stuff about Heading Anchors, you want to read the switch to the newer version (3.1+ and 3.x-dev now) on the front page.
Otherwise, I would think that calling the filter directly would work. The 'prepare' is necessary only in order to support the <-- tableofcontent --> syntax.
Note also that the $format needs to be defined properly (3rd parameter.) It is used to determine the current setup. You are free to create a format just and only for that purpose then use its identifier (that you see in your URL/location bar then you edit the format.)
Thank you.
Alexis Wilke
Comment #2
carvalhar commentedHi Alexis,
I'm using a view tpl...so i have a div where all rows are printed.
I'd like to place the TOC above it..so in my tpl i tried this code:
But the filter doesn't work and toc doesn't show.
Do you know how could i call toc?
I think i should use php for it. There is a function (function theme_tableofcontents_toc($toc) ) but how can i pass this variable $toc?
I'm not sure how to make a php to call the module TOC and its output.
thanks,
Carlos
Comment #3
luco commentedwhat carlos needs - and so do I - is a way to have a Views-compatible TOC.
the first thing that crossed our minds was to add a TOC filter to the view's header, in order for it to call the titles in the view's body. that didn't work, because - probably - the view's header has its own scope. therefore what happens in the header, stays in the header ;]
so we need to know what is the function that converts
into actual links. we'd embed that function staight into the Views TPL and that would hpefully work.
care to help us?
Comment #4
AlexisWilke commentedCarlos & Luco,
Would what I describe here work for you guys?
http://new.m2osw.com/doc_toc_for_views
Thank you.
Alexis
Comment #5
luco commentednope. that's the opposite of what we're trying to accomplish. we're trying to see nodes inside a view, grouped by some criteria (in our case, taxonomy) and whose automatically generated H2s are called by a TOC.
if we insert a view in a node, that means having to repeat it every time a node was published. plus, as your solution stated, it doesn't support dinamically created views. and we need to be able to supply arguments.
Comment #6
carvalhar commentedI'm trying to call TOC using php inside the tpl of my custom view.
But i don't know the configuration of TOC object and also, i couldn't find an easy function as "print_toc($text)"...
I found the function _tableofcontents_replace_toc($format, $text) inside tableofcontents.pages.inc and i tryed to adapt it, but i couldn't succeed.
Do you have any tips how to "print" TOC using php?
Thanks,
Carlos
Comment #7
AlexisWilke commentedLuco,
The views are updated in nodes when you use [view:<name>] (unless you have some cache going on)
So adding new entries that appear in the view will update the node automatically.
The problem is arguments if you need dynamic arguments to the view. You can add static arguments though. So if you just have 4 or 5 specific arguments, it would work just fine to create 4 or 5 nodes with a [view] tag.
Luco & Carlos,
Try something more like this:
If you want a <div> around the [toc], then add that inside the string '<div ...>[toc]</div>'. Similarly, you can wrap the rows and the entire page.
The 2 in the call is the format number. Please, go to your admin/settings/filter and check the format number that includes support for [toc]. If you don't yet have such a format, create one or edit one and add the [toc] filter to it.
Thank you.
Alexis
Comment #8
carvalhar commentedHi Alexis,
thanks a lot for your php code!
It worked fine in my tpl, i could print the TOC and the links are fine too.
Just two lines and everything loads fine.
thanks :)
Carlos
Comment #9
luco commentedyeah, we tried without changing the first argument (the number "2"), then we changed to 0, didn't make any difference.
anyway it worked - it's all that matters ;]
thanks a bunch.
Comment #10
AlexisWilke commentedGlad it worked 8-)
I added a new page to my Drupal site here: http://new.m2osw.com/drupal_doc_toc_dynamic_views
It explains the same thing as I just mention in this post.
Note that the number "2" does not matter if the default [toc] tag works for you. If you want to be able to change the defaults, then you will need to make use of a filter appropriately.
Thank you.
Alexis Wilke