usability1Add my vote for this tag create new tag
, view all tags

Proposed: Automatic window title based on first heading in topic

ALERT! NOTE: This proposal is replaced by VarTOPICTITLE and TopicDisplayName.

You get nice window titles if you pull the first heading from the topic and use it as the window title text. This proposed feature allows you to do that automatically. It is enabled with preferences settings, e.g. it can be set flexibly site-wide, per web or per topic.

  • Set NICEWINDOWTITLE = on or Actual window title with optional $topic, $web and $heading

If the setting is set to on on SomeTopic (on site-wide, web-level or topic level), the window title will be set to the First heading text of SomeTopic. If there is no heading, it will be set to the topic name.

If the setting is set to an Actual window title, the Actual window title will be shown in the browser. Optional tokens $topic, $web are expanded to topic name and web name, respectively. Optional token $heading is expanded to the first heading in the topic, or $topic if there is none.

This setting makes it compatible with the current spec:

  • Set NICEWINDOWTITLE = $topic < $web < %WIKITOOLNAME%

This is consistent with the proposed AutomaticLinkLabelBasedOnHeading feature.

-- Contributors: PeterThoeny


Introduce a Page Title Variable

The request is to introduce a variable named TOPICTITLE that can be used to set the title of the page.

This request is based on a suggestion from the discussion about ReversePageTitle.

I have suggestion about this:

Why don't we change the twiki.pattern.tmpl like this:

 <title> %TOPICTITLE% </title> 

Then we define the following variable in WebPreferences:


This will have the added benefit that now the title can be changed web-wide (using the variable in WebPreferences) and page-wide using the following invisible code:

         * Set TOPICTITLE = My topic on my web.

Altogether a discussion like in this topic can be totally avoided, because everybody can define the title at will. Suggestions on this?

A patched wiki using this change to the pattern-skin can be found at http://page.mi.fu-berlin.de/~oezbek/cgi-bin/view/TestSE/WebHome.

-- ChristopherOezbek - 04 Oct 2004

Is it problematic / useful if this variable can be overridden in the topic text? In other words, should it be included in the FINALPREFERENCES of the Web's WebPreferences?

-- ArthurClemens - 04 Oct 2004

I think the whole point is to allow it to be set per topic. To avoid setting it accidentially, how about naming it TOPICTITLE instead?

-- PeterThoeny - 05 Oct 2004

It would be defintely be a feature that is especially designed to allow the title to be set per topic. It is mainly a step to make Google search results more readable.

-- ChristopherOezbek - 07 Oct 2004

What I'd realy like would be the ability to set titles site wide to be a form field or the first heading in a topic. The ability for it to fall back to headings if the form is not present would be good. Would probably have to be done as a plugin. If this variable was in the templates then I guess all the plugin would have to do would be to overwrite whatever the site setting was, unless it was set in the topic.

-- SamHasler - 07 Oct 2004

That's a good idea with the forms and works nicely alongside the =TITLE=-tag. I have incorporated it into my test-twiki at http://projects.mi.fu-berlin.de/w/bin/view/SE/FOSSHome

Since I am pretty new to TWiki, I don't know how complicated a plugin would be that extracts the title information from the first top-level heading, but if you guys want I can have a look.

-- ChristopherOezbek - 21 Oct 2004

Alright, I tried to write a plugin that adds a Set TOPICTITLE = ... depending on the top-level entry of the TOC, but the plugin architecture is not made to accomodate changes to the preferences by the commonTagHandler (preferences are only parsed once and cannot be modified using TWiki::Func). It seems that the only solution would be to use the renderHandler which is said to be expensive. But unfortunately this is not possible either since the header of the html file is not passed into the plugin at all. As a last resort I tried to modify the topic-text before the preferences are initialized, but this fails because the topic is not passed along to initialize1. Any suggestions?

-- ChristopherOezbek - 21 Oct 2004

I have a three line fix for the whole problem, which on the other hand might destroy the security model of TWiki. I added a function called setPreferenceValue which allows modification of the requestPrefs and added another one that gives access using TWiki::Func.

And it works even though I just discovered a problematic situtation: My professor uses the convention to remove the top-most toc-entry using !! because it is kind of redundant to have the title of the page to appear in the toc.

-- ChristopherOezbek - 21 Oct 2004

Can you post those changes here? I'd be very interested in trying this out and testing it on my own site. Thanks!

-- ClausBrod - 18 Dec 2004

--- Prefs.pm.old        2004-05-29 08:51:35.000000000 +0200
+++ Prefs.pm    2005-01-03 15:56:10.000000000 +0100
@@ -834,6 +834,24 @@
 # =========================
+---+++ sub setPreferenceValue( $theKey, $theValue  )
+Will set the given preference value.
+sub setPreferenceValue( $theKey, $theValue  )
+    my ( $theKey, $theValue ) = @_;
+    $requestPrefs->_insertPreference($theKey, $theValue);
+# =========================
 =end twiki


--- TWiki.old   2005-01-03 15:27:46.000000000 +0100
+++ TWiki.pm    2005-01-03 18:28:59.000000000 +0100
@@ -2460,6 +2460,8 @@
     my $tabs = "";
     my $anchor = "";
     my $highest = 99;
+    my $toctitle = "";
+    my $highestToc = 99;
     foreach $line ( @list ) {
         if( $line =~ /^.*<pre>.*$/io ) {
             $insidePre = 1;
@@ -2492,11 +2494,16 @@
             if( ( $line ) && ( $level <= $depth ) ) {
                 $anchor = TWiki::Render::makeAnchorName( $line );
+                if ($level < $highestToc){
+                   $toctitle = $line;
+                   $toctitle =~ s/$regex{headerPatternNoTOC}//go; # We ignore !! and %NOTOC%
+                   $highestToc = $level;
+               }
                 # cut TOC exclude '---+ heading !! exclude'
                 $line  =~ s/\s*$regex{headerPatternNoTOC}.+$//go;
                 $line  =~ s/[\n\r]//go;
                 next unless $line;
-                $highest = $level if( $level < $highest );
+               $highest = $level if( $level < $highest );
                 $tabs = "";
                 for( $i=0 ; $i<$level ; $i++ ) {
                     $tabs = "\t$tabs";
@@ -2523,6 +2530,10 @@
             $result =~ s/^\t{$highest}//gm;
+       if ($toctitle){
+           &TWiki::Prefs::setPreferenceValue( "TOCTITLE", $toctitle );
+       }
         $result = "<div class=\"twikiToc\">$title$result\n</div>";
         return $result;
@@ -3157,8 +3168,9 @@
     &TWiki::Prefs::handlePreferencesTags( $text );
     handleInternalTags( $text, $theTopic, $theWeb );
+    my $handledToc = &handleToc($text,$theTopic,$theWeb,"");
     $text =~ s/%TOC{([^}]*)}%/&handleToc($text,$theTopic,$theWeb,$1)/ge;
-    $text =~ s/%TOC%/&handleToc($text,$theTopic,$theWeb,"")/ge;
+    $text =~ s/%TOC%/$handledToc/ge;
     # Codev.FormattedSearchWithConditionalOutput: remove <nop> lines, possibly introduced by
     # SEARCHes with conditional CALC. This needs to be done after CALC and before table rendering

That is a quick and dirty patch on a Cairo Release. Be aware that you incure the overhead of the call to handleToc for all topics, even if they don't have one with this patch.

You will also need the following addition to the WebPreferences:

   * To use the title of the toc as the title of the page use:   

And a change in the twiki.*.tmpl that you are using:

<title>%TMPL:P{"titleaction"}% %TOPICTITLE% </title>

I have updated the link above to point to a current test-page.

-- ChristopherOezbek - 03 Jan 2005

We have moved our productive version to use the change and the titles are produced just fine. Have a look at http://projects.mi.fu-berlin.de/w/bin/view/SE/FOSSHome

-- ChristopherOezbek - 27 Jan 2005

I just created YouAreHereUsingMetaName because i had overseen this interesting topic. Basically i was asking vor changeing what is being displayed in You are here. Could this be integrated here?

-- WolfgangAlper - 15 Mar 2005

I found a twiki site that work similar to what i mean.

-- WolfgangAlper - 16 Mar 2005

That is a long overdue non-updated site of mine! In fact that was the start of PatternSkin (hence the name). But the topic names in the breadcrumb (I suppose you mean the trail at the top, see also the pattern about this) are created with UnderscoreWikiWords. So not really with page title variables - I think that is a better approach.

-- ArthurClemens - 16 Mar 2005

Yes i noticed that it is using UnderscoreWikiWords and i would also prefer to use topicvars or metadata instead. However the result (breadcrumb) is exactly what i am looking for wink I think If any topic could have an alias, then the creating of informative breadcumbs and pagetitles would be easily achieved.

-- WolfgangAlper - 17 Mar 2005

Christopher, why are you using the name TOCTITLE? It seems this is meant to be the title of the page as seen in the browser window, thus the HTMLPAGETITLE or something? TOC sounds like Table of Contents...

Wolfgang, I think this can be done with TopicVarsPlugin. In a recent project I have used this plugin with an extra form field Pagetitle (and a variable CLIENTNAME set in the WebPreferences) . The homeward path was created like this:

<div class="twikiHomePath">
You are here: [[%WEB%.WebHome][%WebPreferences.CLIENTNAME%]] %META{"parent" formfield="Pagetitle" nowebhome="on" format=" <span class='twikiSeparator'>&gt;</span> [[$web.$topic][$formfield]]"}% <span class='twikiSeparator'>&gt;</span><strong> %FORMFIELD{"Pagetitle" topic="%TOPIC%" format="<nop>$value" alttext="<nop>%TOPIC%"}% </strong>

This results in (example):

You are here: Mercedes > Mercedes C-klasse

-- ArthurClemens - 17 Mar 2005

Arthur, thanks for the snippet. I'll try the suggested way, preferable using MacrosPlugin instead of TopicVarsPlugin if this is possible.

I also suggest/agree to use a different name than TOCTITLE as it can be a bit confusing. At least it was for me wink

-- WolfgangAlper - 18 Mar 2005

Following the links of my contributions to twiki pages, I came across something I wrote a few months ago: HowToShowParentTopics#New_proposal_add_formfield_to_ME. It has a patch to let META{"parent"} use $formfield, and another patch to let it use $format.

So the code snippet above will only work with the patches from HowToShowParentTopics (now in AddFormfieldParamToMetaParent and AddFormatParamToMetaParent).

-- ArthurClemens - 26 Mar 2005

Hi Arthur! here is the procedure I use:

  • The TOC is scanned and updates the variable TOCTITLE
  • The TOCTITLE can then be used to set the TOPICTITLE variable which I use in the template. This could be renamed into HTMLPAGETITLE for clarity, indeed.

Here an example:

   * Set TOCTITLE = !%TOPIC% - Has No TOC 

This will display the topic name and "Has No TOC" and the web for all topics that don't have a single heading. If there is a TOCTITLE it will overwrite the previous value (PageTitleVariable - Has No TOC) and can thus be used in the variable TOPICTITLE.

-- ChristopherOezbek - 28 Jun 2005

Hello TWiki-Team, I would like to ask what do I have to do to get this feature added into Dakar release or is it already too late?

I have been using the above patch in a TWiki Alpha release and the only problem it still has is that it does not strip exclamation marks that are used as nop.

If somebody gives me a hint what needs to be done, I would be willing to polish the patch accordingly.

-- ChristopherOezbek - 31 Aug 2005

Tell me the spec of what you want to do, and I can advise. I can't reverse engineer it from this topic, I'm afraid.

-- CrawfordCurrie - 31 Aug 2005

Hi Crawford, there are two things:

  • Introduce !%HTMLPAGETITLE% as a variable that is set in the WebPreferences to %TOPIC% < %WEB% < %WIKITOOLNAME% and change the view.tmpls accordingly.
    This change allows the page title to be set from each topic and for each web.
  • Add the following function to Prefs.pm.
--- Prefs.pm.old        2004-05-29 08:51:35.000000000 +0200
+++ Prefs.pm    2005-01-03 15:56:10.000000000 +0100
@@ -834,6 +834,24 @@
 # =========================
+---+++ sub setPreferenceValue( $theKey, $theValue  )
+Will set the given preference value.
+sub setPreferenceValue( $theKey, $theValue  )
+    my ( $theKey, $theValue ) = @_;
+    $requestPrefs->_insertPreference($theKey, $theValue);
+# =========================
  • Patch handleToc and the place where it is called.

I guess the concerns against this change are the following:

  • Will need some work in the templates and preferences.
  • The second point might be a security problem. If this is too severe, then I can supply another solution which works directly in TWiki.pm (this the big patch given above in my post from 3th January).
  • What the third point is doing is basically parsing the TOC and saving the value as a new preference variable. I could not figure out how to do this as a plugin (see second post from Octobre 21st.

I appreciate the help! Send me a mail for faster commuication twiki@oeziPLEASENOSPAM.de, if you prefer.

-- ChristopherOezbek - 01 Sep 2005

What would be the prefered way for me to contribute this to TWiki? Should I write a big patch against a current SVN snapshot?

I still think it would be great to have automatically set topic titles like

Introduce a Page Title Variable < Codev < TWiki

instead of

PageTitleVariable < Codev < TWiki.

-- ChristopherOezbek - 06 Dec 2005

Yes, please bring this to Dakar or at least prepare it for the journey to Edinburgh. smile

-- FranzJosefSilli - 06 Dec 2005

Hi Franz, I had a look into a current develop (7837) release and tried to port the patch, but it seems like there were changes in the way the topics get rendered. For the above patch to work it is important that the topic text is expanded before it is inserted into the view.tmpl at the position %TEXT%. Is it possible that this aspect changed?

In other words:

Is it possible to modify a preference value from a plugin such that a variable is expanded later-on with the value that the plugin set?

-- ChristopherOezbek - 15 Dec 2005

Whats the solution in DakarRelease now to override the HTML title (with top most heading)?

-- TobiasRoeser - 09 Feb 2006

This has not been developed into Dakar.

In the WikiMatrix I noticed that TikiWiki has a markup syntax for the window title: -= Titlebar =-=

In TWiki markup this would be logical:

---= overriding window title
---+ header 1
---++ header 2

-- ArthurClemens - 09 Feb 2006

Related, DokuWiki offers [[Page]] links that render as Page in case the page does not have a heading, and renders as First Heading in case there is one. This is very intuitive and easy to use.

How about these new preferences settings:

  • Set NICELINKLABEL = Any label
  • Set NICEWINDOWTITLE = Any title
Either one can be set to on (to take the value from the first heading), or it can be set to the actual text. The NICELINKLABEL does it the DokuWiki way; the NICEWINDOWTITLE does it the TikiWiki way. Since these are preferences settings, it can be set flexibly site-wide or per topic.

-- PeterThoeny - 09 Feb 2006

I updated above proposal accordingly.

See also related AutomaticLinkLabelBasedOnHeading.

-- PeterThoeny - 09 Feb 2006

Got a PAGETITLE variable in the NatSkin that is inserted into a condition

  %IFDEFINEDTHEN{"%PAGETITLE%" action="view|preview|save|edit"}%
  %ELSIFDEFINED{"%FORMFIELD{"Headline"}%" action="view|preview|save|edit"}%
  %ELSIFDEFINED{"%FORMFIELD{"TopicDescription"}%" action="view|preview|save|edit"}%
    %TOPIC% - %FORMFIELD{"TopicDescription"}%

In other words If the current action is view, preview, save or edit

  1. If PAGETITLE is defined use it
  2. or if a formfield Headline is defined use that
  3. or if a formfield TopicDescription is defined use that
Or fallback to the TOPIC name. This matches nicely the BlogPlugin to give you the "right" title automatically.

-- MichaelDaum - 10 Feb 2006

Has anybody developed a solution/patch against Dakar to change/set a topic variable, as the upper patch to Prefs.pm don't work anymore?

-- TobiasRoeser - 22 Feb 2006

About a more general solution: see proposal in TopicDisplayName.

-- ArthurClemens - 22 Feb 2006

This proposal is now replaced by VarTOPICTITLE and TopicDisplayName.

-- PeterThoeny - 2012-05-11

Edit | Attach | Watch | Print version | History: r36 < r35 < r34 < r33 < r32 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r36 - 2012-05-11 - PeterThoeny
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2017 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.