Overriding the $menu / $button variables

Overriding the $menu / $button variables

av Tom Black -
Galle vástádusa: 6
Hi folks,

I'm taking my first foray into theme writing today, and while some of it is going okay, I'm stumped on how to change / override the $menu variable, so that instead of

"You are logged in as Admin User (Logout)"

it returns something more like :
newmenu.gif
with the links seperated out into images.

There was a thread that suggested looking at the Theme Description, with a link to the docs, but that was from 2005 or so, and I can't see the description documents anywhere!

Ideally I want to keep any changes or code within the theme itself, and if at all possible I don't want to modify core code.

Please help!


Gjennomsnittlig vurdering: -
Vástádussan geasa: Tom Black

Re: Overriding the $menu / $button variables

av Frank Ralf -
Hi Tom,

CSS FAQ and Themes FAQ are good starting points for learning more about CSS and theming. You will also find some concrete examples there which should point you in the right direction.

If you don't want to replace the text links completely by images (which might create an accessibility/usability problem) you could use CSS for providing the images as background images to the text links (http://reference.sitepoint.com/css/background-image).

hth
Frank

Vástádussan geasa: Frank Ralf

Re: Overriding the $menu / $button variables

av Tom Black -
Thanks, let me rephrase the question though:

By default, the $menu variable in the header / footer.html files returns 'You are logged in as....' and the language select menu.

The 'you are logged in as...' bit is provided by the user_login_string() function, in lib/weblib.php

Without editing the contents of weblib.php, is there a way of changing the contents of the $menu variable within a theme, or should I just add php code to check if someone is logged in, and who they are?


Vástádussan geasa: Tom Black

Re: Overriding the $menu / $button variables

av Frank Ralf -
The function pulls its text from the language file moodle\lang\en_utf8\moodle.php via the get_string() function.

So you might have a look at the documentation on Language editing.

hth
Frank
Vástádussan geasa: Frank Ralf

Re: Overriding the $menu / $button variables

av Frank Ralf -
Well, that might be part of the solution...

You might also have a look at Header logo to get an idea how to change the header. And you could at some other themes how they do it: http://moodle.org/mod/data/view.php?id=6552

hth
Frank
Vástádussan geasa: Frank Ralf

Re: Overriding the $menu / $button variables

av Frank Ralf -
The best solution I could think of is to directly override the $menu variable in your theme's header.html file. After all, you can use any PHP there you want.

So here's my solution which makes heavy use of regular expression to dissect the HTML in $menu and then re-assemble the parts in the desired new order:

<div class="headermenu">
          <?php
            $menu = preg_replace('/You are logged in as/', 'Logged in:', $menu);
            $menu = preg_replace(
              '/(<div\s+class="logininfo">)  # $1 starting point
                ([^<]*?)                                  # $2 login text
                (<a\s+href=[^>]+>)              # $3 first link
                ([^<]*)                                    # $4 User name
                .+?
                \(                                            #    opening parenthesis
                (<a\s+href=[^>]+>)              # $5 second link
                ([^<]*)                                    # $6 "Logout" link text
                (.+?div>)                              # $7 the rest until the closing div
              /six',
              '$1 $2 $4 $5[$6]</a> $3[Edit profile]</a></div>',
              $menu);
              echo $menu;
          ?>
        </div>

The result should look similar to the screenshot. Replacing the text links with images is left as an exercise to the reader ;-)

Cheers,
Frank

"Regular Expressions Tester" for Firefox was a big help: https://addons.mozilla.org/en-US/firefox/addon/2077

Mielddus Login_header.png