TWiki Usability Tricks Pt1: Turn your index into a sitemap
If you are scanning one of the current indexes (
WebTopicList and
WebIndex) for a specific topic you have no idea which other topics are related e.g. which topics are child topics.
With the help of
TreePlugin you can easily turn your index into a sitemap.
As you can see in the screenshot all topics are displayed by hierarchy and alphabet.
How To:
- The top level topic in this example is the WebHome (renamed in this example).
- Therefore the WebHome needs to be the root of all topics in your web.
- To get all the Web* Topic out of the normal list I introduced a topic called "SystemSeiten" (which means SystemTopis)
- This topic becomes root topic of all topics that start with Web*.
- To keep the indexes in the TWIKIWEB intact and update safe I created a topic called WebSiteMap in my TWIKIWEB with the following code:
---+ Site Map of %BASEWEB%
*Site maps in other webs:*: %WEBLIST{format="[[$name]]" separator=", "}%
<div style="border:1px solid silver; background:#EFEFEF; padding:10px; font-size:90%; line-height: 1.5;">
%TREE{web="%BASEWEB%" formatting="ullist"}%
</div>
- This produces the above output.
- If you simply put
%INCLUDE{"TWiki.WebSiteMap"}% in each of your webs index topics you have a handy site map and index in one.
- and you can easily jump to sitemaps in other webs.
NOTE: This was tested on Twiki installation with relatively few topics. I don't know how this works if you have several thousands of topics. But it works very well on our TWiki.
The next step would be to use some JavaScript to fold and unfold the hierarchy levels.
Comments
FranzJosefGigler - 12 Sep 2007:
Carlo, have you ever tried
TreeBrowserPlugin?
CarloSchulz - 13 Sep 2007:
I tried to combine it with
TreePlugin but I had give up on this one because it didn't work as documented.
MarcoSilva - 16 Sep 2007:
Nice tip, I would like to try but without the
TreePlugin? , using only inline search did you try ? Maybe with METASEARCH variable. Anyway thks the tip.
SteveJonesST - 19 Sep 2007:
Hi Carlo.
I got the TreeBrowser and TreePlugin working together like this:
%TREEBROWSER{"thread" title="<h3>Topic Tree Of %WEB%</h3>" openAll="on"}%
%TREEVIEW{formatting="outline" format="* [[$topic]]" levelprefix=" "}%
I put one of these in every new web created. Hope it's helpful.
JacekZapotoczny - 20 Sep 2007:
We wanted to publish sitemaps from selected webs on a
Main. To do this we've used formatting as stated above by Steve. But unfortunately including such a number of sitemaps to a single topic was time consuming while the loading time of a homepage was crucial for us. Then we've found a plugin combination which helped us (
TwistyPlugin,
TreePlugin,
TWikiAjaxContrib). Here I'll try to explain the essentials.
First (TreePlugin) for each web there was created a WebSiteMap topic with the following content:
%TREEVIEW{web="%WEB%" excludetopic="Web*" formatting="outline" format="* [[%WEB%.$topic][$topic]] " levelprefix=" "}%
Next (TwistyPlugin) On Main.WebHome we've defined for each of the topics the following:
[[WEB1.%HOMETOPIC%][ __WEB1 web__ ]]
%TWISTY{id="WEB1SiteMap" mode="div" showlink="Show !SiteMap..." hidelink="Hide !SiteMap"
showimgleft="%ICONURLPATH{toggleopen-small}%"
hideimgleft="%ICONURLPATH{toggleclose-small}%" remember="on"}%
<div id="WEB1SiteMap" style="border-left:1px solid grey"></div>
%ENDTWISTY%
[[WEB2.%HOMETOPIC%][ __WEB2 web__ ]]
%TWISTY{id="WEB2SiteMap" mode="div" showlink="Show !SiteMap..." hidelink="Hide !SiteMap"
showimgleft="%ICONURLPATH{toggleopen-small}%"
hideimgleft="%ICONURLPATH{toggleclose-small}%" remember="on"}%
<div id="WEB2SiteMap" style="border-left:1px solid grey"></div>
%ENDTWISTY%
(...)
where
WEB1 and
WEB2 are the names of existing webs.
And last (TWikiAjaxContrib), we've added some JS code to fill up
div's with a content on demand (onclick).
To do that first add some JS to the page header with
%AJAX% tag placed at the begining of the page. Then place the following to the bottom of the page.
<script type="text/javascript">
// <![CDATA[
// Load onclick
twiki.AjaxRequest.setProperties( "WEB1SiteMap", {container:"WEB1SiteMap", url:"%SCRIPTURL{"view"}%/WEB1/WebSiteMap?skin=text", cache:true });
twiki.AjaxRequest.setProperties( "WEB2SiteMap", {container:"WEB2SiteMap", url:"%SCRIPTURL{"view"}%/WEB2/WebSiteMap?skin=text", cache:true });
var myrules = {
'#WEB1SiteMapshow' : function(el) {
var oldOnClick = el.onclick;
el.onclick = function() {
twiki.AjaxRequest.load("WEB1SiteMap");
oldOnClick();
return false;
}
},
'#WEB2SiteMapshow' : function(el) {
var oldOnClick = el.onclick;
el.onclick = function() {
twiki.AjaxRequest.load("WEB2SiteMap");
oldOnClick();
return false;
}
}
};
Behaviour.register(myrules);
//Failure handler
function handleFailed(inName, inStatus) {
var msg = "<div style=\"background:#ffc; padding:.5em;\">" +
"Could not load contents." +
"<\/div>";
twiki.HTML.setHtmlOfElementWithId(inName, msg);
// alert(msg);
}
// ]]>
</script>

The trick is we don't load WebSiteMaps just on homepage open but only when the user requests it. This saves a lot of time on homepage load which takes now 1.6s according to Apache Benchmark. And the last but not least it looks pretty fancy on the page
CarloSchulz - 20 Sep 2007:
Sweet, thanks a lot everyone. Will try to refactor this into a new article.