# Menu Generation Program

> Source: https://manual.pvxplus.com/inomads/menu-generation

When creating a new template using **[Template Designer Wizard](https://manual.pvxplus.com/inomads/template-designer-wizard)** or modifying an existing template using **[Template Maintenance](https://manual.pvxplus.com/inomads/template-maintenance)**, you can **[Define a Menu](https://manual.pvxplus.com/inomads/template-designer-wizard#definemenus)** to add to a section of the template.

If you want to define a simple menu with static contents, you can enter the individual menu components in the **[Menu Contents](https://manual.pvxplus.com/inomads/template-designer-wizard#contents)** grid (the **[Define Menus](https://manual.pvxplus.com/inomads/template-designer-wizard#definemenus)** window in the Template Designer Wizard or the **[Menus](https://manual.pvxplus.com/inomads/template-maintenance#menustab)** tab in Template Maintenance). However, situations may arise where other factors need to be considered when creating the menu contents. For example, the data source for the menu changes periodically or security checking needs to be applied to the menu contents. To define a menu that will address these types of situations, you can create a PxPlus program to generate the menu contents and then enter that program name in the *Menu Generation Program* field in the **[Define Menus](https://manual.pvxplus.com/inomads/template-designer-wizard#definemenus)** window in the Template Designer Wizard or the **[Menus](https://manual.pvxplus.com/inomads/template-maintenance#menustab)** tab in Template Maintenance. A Menu Generation program eliminates the need to define the menu contents manually. Once the name of a Menu Generation program is entered, you can then specify other menu settings such as layout, border, background color/image, text color, etc.

*(The ability to specify a Menu Generation Program was added in PxPlus 2016.)*

Note:  
When defining a menu within Template Designer Wizard or Template Maintenance, you must either enter a Menu Generation Program or enter menu contents in the Menu Contents grid. If a Menu Generation Program is entered, the Menu Contents grid will not be available for entry.

This page explains how you can create your Menu Generation program to generate menu contents.

To give you an example, the ***ide*** template was used to generate the interface below. You can select this template in **[Template Maintenance](https://manual.pvxplus.com/inomads/template-maintenance)** and look at the settings on the **Sections** tab. When **Section 2** is selected, the **Section Contents** grid indicates that a menu with *Menu Name=main* has been defined with its positioning on the bottom of this section, horizontally centered. The **Menus** tab shows that the menu was generated by running the *Menu Generation Program* **\*ide/inomads/imp_ide.mnu**. This section with its menu defined is highlighted below.

![](https://manual.pvxplus.com/migration-assets/e05331443d682ce4b87bf1051a86806d531fccfefe053fd61eb744025b771768.png)

To guide you in creating your Menu Generation program, you may find it helpful to review the code in the **\*ide/inomads/imp_ide.mnu** program using **[\*IT - Integrated Toolkit](https://manual.pvxplus.com/toolkit1/overview)**, **[Ed+](https://manual.pvxplus.com/ed-program-editor)** or any other program editor.

When iNomads runs a template with custom menu settings defined, the menu data is read from the template's *custom.ini* file for processing. Each menu and sub-menu is assigned a menu number. If a Menu Generation program has been specified, the iNomads program creates a memory file and passes the file handle *(menu_mem)*, along with the current menu number *(menu_no)*, to the Menu Generation program. The Menu Generation program is responsible for populating the memory file, using a specific record format. If sub-menus are required, the value of *menu_no* may be incremented. When completed, the Menu Generation program will EXIT, allowing the iNomads program to merge the records from the memory file and continue processing.

To receive the *menu_mem* and *menu_no* values, every Menu Generation program ***must*** contain the following ENTER statement:

```
ENTER menu_mem,menu_no
```

The format for the write to the memory file is:

```
WRITE(menu_mem, KEY=key$)name$,text$,url$
```

***Where:***

|  |  |
| --- | --- |
| *key$* | To conform to the formats of the menus defined in the *custom.ini* file, the key value must be in the following format:<br>"\[Menu"+STR(*mnuNo*:"00")+"\_"+STR(*mnuSeq*:"**00")+"\]"**<br>***Where:***<br>*mnuNo* is the menu number.  <br>*mnuSeq* is the sequence number for items in the menu.<br>***Examples:***<br>\[Menu01_03\] indicates that this is the key for the third item on Menu One.  <br> \[Menu02_01\] indicates that this is the key for the first item on Menu Two (a sub-menu of Menu One). |
| *name$* | Typically is the name of the task used to generate a new menu name for sub-menus. |
| *text$* | Text to display for the menu selection. See **[Menu Contents](https://manual.pvxplus.com/inomads/template-maintenance#menucontents)** in **Template Maintenance**. |
| *url$* | URL value for the menu selection. Can contain a number of values. See **[Menu Contents](https://manual.pvxplus.com/inomads/template-maintenance#menucontents)** in **Template Maintenance**.<br>***Examples:***<br>\|  \|  \|<br>\| --- \| --- \|<br>\| [http://www.pvxplus.com](http://www.pvxplus.com/) \| For displaying a Web page \|<br>\| menu:name \| For a sub-menu \|<br>\| /inomads?txid=MENU_TRANS *&param1*=VAL1 &*param2*=VAL2 \| For running an iNomads transaction<br>***Where:***<br>MENU_TRANS<br>An iNomads transaction that must be created in iNomads **[Transaction Maintenance](https://manual.pvxplus.com/inomads/transaction-maintenance)**<br>*param1, param2*<br>Parameters that can be retrieved using the iNomads *url_arg$* property<br>VAL1, VAL2<br>Values for the parameters *param1* and *param2*<br>For the menu generation example above, the **\*ide/inomads/imp_ide_mnu** program writes the *url$* values as:<br>/inomads?txid=\_ide_menu&*task*=TASK_ID<br>***Where:***<br>\_ide_menu<br>An iNomads transaction that is defined to run the **\*ide/inomads/inomads_mnu** program<br>TASK_ID<br>A task from the *tasks.dat* file<br>Since TASK_ID could refer to any number of different task types (program, panel, report, etc.), a program was required that would launch each task when it was selected from the menu on the Web IDE page. The **\*ide/inomads/inomads_mnu** program was created, and the value in the *'task'* parameter was retrieved as *trxName$* using the following:<br>trxName$=%inomads'url_arg$("task",ERR=\*NEXT) \| |

When the Menu Generation program is completed, an EXIT statement is needed to return to the calling program.
