Theme 2.0: How to get custom menu working?

Theme 2.0: How to get custom menu working?

autor Aylwin Cal -
Počet odpovědí: 11
I would like to use the custom menu but I can't get it to work. The main problem is that I'm unable to configure the menu items. I keep getting an error... even when I copy-paste the example.

I'm running Moodle 2.0 Preview 3 (Build: 20100603). Any idea what I might be doing wrong?
Příloha custom_menu_error.jpg
Průměr hodnocení: -
V odpovědi na Aylwin Cal

Tento příspěvek ve fóru byl odstraněn

Obsah tohoto příspěvku ve fóru byl odstraněn a již nemůže být zpřístupněn.
V odpovědi na Odstraněný uživatel

Re: Theme 2.0: How to get custom menu working?

autor John St -
Also, (at least for me) the custom menu did not work in an earlier build of preview three. It would not take any menu items I would add via the page you have shown. Even copying the sample text, it would still error out when attempting to save.

I updated to: Moodle 2.0 Preview 3 (Build: 20100616) and it now works fine!
V odpovědi na John St

Re: Theme 2.0: How to get custom menu working?

autor Aylwin Cal -
Thanks for the replies. I was impatient and decided to hard code my own menu. But I'll try updating to a newer build. I'm pretty that should fix the problem.
V odpovědi na Aylwin Cal

Re: Theme 2.0: How to get custom menu working?

autor Mary Evans -
Did you check to see that the Moodle Menu code was in any of the layout pages, either general.php or frontpage.php. Also some of the original Moodle 2.0 themes would not have this facility unless updated to accomodate this new feature, my Flower Power theme certainly hasn't, it would need to be hard coded into the layout pages for it to work.

Just a thought.

Mary
V odpovědi na Mary Evans

Re: Theme 2.0: How to get custom menu working?

autor Aylwin Cal -
Thanks for the input. Yes, the code is there. I'm using the standard theme that comes with Moodle 2.0. Actually, that's how I learned of the custom menu feature. I started modifying the standard theme to suit my needs and noticed the relevant code. Only then did I notice the option to define custom menu items in the theme settings page.

I guess my thread subject is a bit misleading. I don't believe my issue has anything to do with the particular theme I'm using. The main problem I'm having is that I'm unable to save any custom menu items in the theme settings page. Regardless of whether the theme I'm using has the code to display the custom menu, I think I should at least be able to save the actual menu items, right?

-Aylwin-
V odpovědi na Aylwin Cal

Re: Theme 2.0: How to get custom menu working?

autor Mary Evans -
Hi,

I only mentioned about the themes, because I didn't like the way the Custom Menu worked so I deleted the php off my theme layout page. Then after a week or so I thought I'd have another go at using it, and got my own menu worked out and tried to save it but it wouldn't save, then I realised I didn't have the code in my theme, so I just gave up on it assuming it was my fault for removing the code.

But thinking about it now, makes me suspect it might well be a bug!

Mary
V odpovědi na Mary Evans

Re: Theme 2.0: How to get custom menu working?

autor Sam Hemelryk -
Hi Mary,

I was just thinking on what you were saying in regards to the custom menu and thought I might make a suggestion.

I remember reading somewhere that you were in the process of learning PHP which is why I am thinking that you might actually be up for this.

The custom menu is as you know using the YUI3 menunav widget. However it can be changed by overriding the core renderer that is producing it and in particular overriding the render_custom_menu and render_custom_menu_item.

The tutorial on overriding a renderer has a pile of information on how to attempt it if you are keen, and if you decide to give it a shot but want a starting hand let me know, start a thread in this forum and I'll write you a quick start guide.

Cheers
Sam
V odpovědi na Sam Hemelryk

Re: Theme 2.0: How to get custom menu working?

autor Mary Evans -
Hi Sam,

You must have read my thoughts because I was wondering if I could do this to change the way YUI css seems to be taking over my theme! LOL

Thanks for the pointer. I will indeed start a new thread as I am sure I will need a kick start on this.

I'll have a go first and see how far I get.

One other problem I'm having at the moment, or rather something which has me struggling to find a way of doing it, is getting the date to show up in different languages. I'm assuming a get_string would work, but how to tell which day month or year!

Currently my code for the date is...

<a href="<?php echo $CFG->httpswwwroot.'/calendar/view.php'; ?>">
<?php $my_t=getdate(date("U"));
echo("$my_t[weekday], $my_t[mday] $my_t[month] $my_t[year]");?></a>

You can see the date on my site Moodle198 site HERE

However I'm working on a Moodle2 theme where I am employing the same menu with the same date code.

Any thoughts?

Many thanks for your help thus far.

Mary
V odpovědi na Mary Evans

Re: Theme 2.0: How to get custom menu working?

autor Sam Hemelryk -
Hi Mary,

In regards to the date try the following:

<?php
echo userdate(date('U'));
?>

The userdate function is a method in lib/moodlelib.php that returns a formatted string given a UTC timestamp.

Check out the phpdocs page for the userdate function for more information.

Cheers
Sam
V odpovědi na Sam Hemelryk

Re: Theme 2.0: How to get custom menu working?

autor Mary Evans -
Wonderful!!! It works exactly as I want it too...and such a simple line of code too!

Thanks Sam!

Mary
V odpovědi na Aylwin Cal

Re: Theme 2.0: How to get custom menu working?

autor Sam Hemelryk -
Hi Aylwin,

Indeed the there was a bug in Moodle that was preventing the custom menu (+ many other text area admin settings) from saving because of the invalid value error.

The problem was with text cleaning changing newline formats and the solution simple least to say it involved modification of the HTMLpurify library, you can read more about it on MDL-22654 if you are interested.

It has now been fixed in both Moodle 2.0 and 1.9.9, unfortunately it wasn't noticed until after PR3 but should be fine again in PR4. You are of course most welcome to checkout the latest 2.0 from CVS or if you would rather you can always apply the small patch on the tracker issue to fix the bug until PR4 is release.

Cheers
Sam