[Home]WikiPatches/MenuPage

UseModWiki | WikiPatches | RecentChanges | Preferences

Generate A Menu From A Dedicated Page

The ides of this patch is to have a dedicated page which will turn into a menu bar for the whole site.

Having a page called "Menu" with this content:

---------------------- .../wiki.pl?Menu
* Home
* Topic1
* Topic2
** Subtopic1
** Subtopic2
* Topic3
---------------------- 

With the right style sheet, this will turn into a top menu like this: (Subtopics don't show, they are drop down menus; learn it e.g. here: http://www.alistapart.com/articles/hybrid/ )

+---------------------- 
| Home  Topic1  Topic2  Topic3
|
| = WikiPage =
| 
| ...content...
| ...
+---------------------- 

Source code, applied to UseMod-1.0.4:

sub GetHtmlHeader {
[...]
   if ($BGColor ne '') {
     $bodyExtra .= qq( BGCOLOR="$BGColor");
   }
   $html .= "</HEAD><BODY$bodyExtra>\n";
+  $html .= GetMenuText();
+
   return $html;
 }

+sub GetMenuText {
+  my ($fname, $data);
+  my (%MenuText, %MenuPage, %MenuSection);
+
+  # %Section = ();
+  %MenuText = ();
+  $fname = &GetPageFile("Menu");
+  if (-f $fname) {
+    $data = &ReadFileOrDie($fname);
+    %MenuPage = split(/$FS1/, $data, -1);  # -1 keeps trailing null fields
+  } else {
+    return "";
+  }
+
+  my ($name) = "default";
+
+  if (!defined($MenuPage{"text_default"})) {
+    return "";
+  } else {
+    if (!defined($MenuPage{"text_default"})) {
+      return "";
+    } else {
+      %MenuSection = split(/$FS2/, $MenuPage{"text_default"}, -1);
+    }
+    %MenuText = split(/$FS3/, $MenuSection{'data'}, -1);
+  }
+
+  return "<div class=menu id=menu>" . &WikiToHTML($MenuText{'text'}) . "</div>\n";
+}
+
 sub GetFooterText {
   my ($id, $rev) = @_;
   my $result;

[...]

See it in action here: http://www.mustard-seed-faith.de and http://www.sweet-chariot.de Both Wikis are used as community sites to registered users, and appear as a web site to the outside (you).

- KarstenSievert


UseModWiki | WikiPatches | RecentChanges | Preferences
Edit text of this page | View other revisions | Search MetaWiki
Last edited May 4, 2008 1:31 pm by KarstenSievert (diff)
Search: