Bug: TOC{BASETOPIC} from an included page (eg, WebLeftBar) produces TOC of including page
while trying to add a table of contents in
WebLeftBar, adding TOC{BASETOPIC} produces a TOC of
WebLeftBar rather than BASETOPIC. each page on the
TestCases wiki
except http://develop.twiki.org/~develop/cgi-bin/view/TestCases/WebLeftBar
demonstrates the bug (as BASETOPIC in that case
should be
WebLeftBar)
Test case
trying to create a test case at
http://develop.twiki.org/~develop/cgi-bin/view/TestCases/TestCaseAutoTocOfBaseTopicInIncludedPage
, although any page
except http://develop.twiki.org/~develop/cgi-bin/view/TestCases/WebLeftBar
demonstrates the bug
Environment
--
WillNorris - 16 Jan 2005
Follow up
Fix record
i haven't fully sussed out the data flow, however, the following patch provides correct (although slower) output
wbniv:~/twiki/DEVELOP2/lib wbniv$ svn diff
Index: TWiki.pm
===================================================================
--- TWiki.pm (revision 3474)
+++ TWiki.pm (working copy)
@@ -1507,10 +1507,7 @@
my $result = "";
my $line = "";
my $level = "";
- if( "$web.$topicname" ne "$defaultWeb.$defaultTopic" ) {
- my %p = ( _DEFAULT => "$web.$topicname" );
- $text = $this->_handleINCLUDE( \%p, $defaultWeb, $defaultTopic );
- }
+ $text = $this->_handleINCLUDE( { _DEFAULT => "$web.$topicname" }, $defaultWeb, $defaultTopic );
my $headerDaRE = $regex{headerPatternDa};
my $headerSpRE = $regex{headerPatternSp};
--
WillNorris - 16 Jan 2005
This bug applies to Cairo as well (i.e. DEVELOP inherited the bug from there).
The problem is the way templates are expanded into topics. The value of BASETOPIC is quite correct.
What happens is this:
- We are rendering FredFlintstone, using pattern skin
- The template view.pattern.tmpl is expanded
- The TOCs in the expanded template are processed
However the expansion of the template in 2 is
done in the context of the including topic - thus it
thinks the
current topic is
FredFlintstone when it is expanding the text of the
template.
Basically we have to persuade it to expand TOC in the template differently to TOC in the including topic. That can be done in View.pm; though it smells like a hack. The root problem is really this semantic confusion between topics, templates, and included files

As a workaround, I've made it re-read the topic if the _DEFAULT parameter is explicitly given (i.e. diabled the optimisation for that case). Rev 3509.
I'd be interested to hear whether people think this fix should go in. Basically it changes the semantics so that %TOC{"!TocOfBaseTopicInIncludedPage"}% in a template generates a TOC of the BASETOPIC only, whereas currently it generates a TOC of the template only.
--
CrawfordCurrie - 16 Jan 2005
What about the possibility simply of
making all TOC links relative? That way, they would always work with the page as rendered, assuming the targeted anchor is present. I've been wanting to ask about this possibility anyway because it would allow one to send a TWiki topic (with TOC) within body of an html email and have the TOC link to the body of the email and not back to the web site.
--
LynnwoodBrown - 13 Feb 2005
Here's a little hack that cleans up the error without producing TOC when viewing the BASETOPIC:
%%CALC{$IF($EXACT(%BASETOPIC%,%HOMETOPIC%),HOMETOPIC,TOC{"%HOMETOPIC%"})}%%