Thank Goodness! A few minutes ago, I just found a nice trick how we can change the Menu Text on the fly easily and quickly by using the Menu_Rendering of Server Event in PHPMaker 10. In other words, let's say we want to change the Text that belongs to one of the Menu Items without having to either customize the generated code or customize the PHPMaker template files. Just for your information, this trick has not been documented in the Help file of PHPMaker. So I'm really sure you're gonna love it. 🙂
This following trick is very useful if you want to customize your Menu Text or Caption, for example, by adding the certain character or a small icon that precedes the Text of Menu Item. One of the use cases of this is, if you want to give a flag for the certain Menu Item that represents the active Theme for your web application. Yeah, just like a toggle flag for the Menu Item, so that user will know which theme that related to the Menu Item is currently active or selected by the logged in user.
But, in this trick below, we will not go too deep into that case. The example below will only give you the idea how we can change the certain Menu Text easily and quickly by using the powerful of Server Event in PHPMaker.
[hidepost]
Assume I have already a Menu Item which has the Text value of Blue. Then I want to change the Text by adding a "v" character before the Text Menu. Just for simplicity, I am using the "v" character. You may change it by using IMG tag in order to display a small icon that related to the "checked" character.
Okay, so here is the solution. Simply insert the following code into your Menu_Rendering server event:
$Menu->FindItemByText("Blue")->Text = "v Blue";
Please note that if your web application uses Multi Language feature, then you have to handle the possibilities of the Menu Text in another language phrases. For example, my web application uses English and Indonesian languages, then that code above should be like the following:
global $gsLanguage; if ($gsLanguage == "id") { // check whether the Menu Text is in Indonesian $Menu->FindItemByText("Biru")->Text = "v Biru"; } else { // assume default language always in English $Menu->FindItemByText("Blue")->Text = "v Blue"; }
The alternative way to change the Text of Menu Item besides using FindItemByText() function as shown above, is by using FindItem() function; which has one parameter: The Menu ID.
For example:
$Menu->FindItem(1234)->Text = "New Menu Caption";
As we can see, the value of 1234 in that example above is the ID of the Menu Item. Don't forget to adjust it with yours.
[/hidepost]
what about removing a single menu item. I am trying to accomplish removing certain menu items based on user level. Some of the items in the menu are links i created which i love but it should be integrated further I think.
To remove a single menu item, then you may simply use MenuItem_Adding server event, for example: