Skip to content

Commit 629489a

Browse files
Complete documentation for new flexible menu item API
Co-authored-by: nonprofittechy <7645641+nonprofittechy@users.noreply.github.com>
1 parent dcb771e commit 629489a

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed

docs/components/AssemblyLine/magic_variables.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,89 @@ the value of `user_ask_role` is checked.
457457

458458
It is then used to make the question about `other_parties` dynamic.
459459

460+
### `al_menu_items_custom_items`
461+
462+
`al_menu_items_custom_items` allows you to add custom menu items to the dropdown/hamburger menu that appears in the interview navigation. Custom items are displayed before the default Assembly Line menu items (such as "Start over", "Exit and delete my answers", etc.).
463+
464+
This variable should be a list of dictionaries, where each dictionary represents a menu item. Each menu item should follow the standard Docassemble menu item format with these keys:
465+
466+
- `url` (required): The URL that the menu item should link to
467+
- `label` (required): The text displayed for the menu item
468+
- `hidden` (optional): A boolean value that controls whether the menu item is visible. If `True`, the menu item will not be shown
469+
470+
#### Basic static menu items
471+
472+
For simple static menu items, you can use a `data` block:
473+
474+
```yaml
475+
---
476+
variable name: al_menu_items_custom_items
477+
data:
478+
- url: https://example.com/help
479+
label: Help and Support
480+
- url: https://example.com/about
481+
label: About this form
482+
```
483+
484+
#### Dynamic menu items with show/hide logic
485+
486+
For menu items that should appear or disappear based on user choices, use a `data from code` block with the `reconsider` modifier:
487+
488+
```yaml
489+
---
490+
reconsider: True
491+
variable name: al_menu_items_custom_items
492+
data from code:
493+
- url: |
494+
"https://example.com/help"
495+
label: |
496+
"Help and Support"
497+
- url: |
498+
url_ask(['download_progress'])
499+
label: |
500+
"Download my progress"
501+
hidden: not user_logged_in()
502+
- url: |
503+
"https://example.com/advanced"
504+
label: |
505+
"Advanced options"
506+
hidden: not showifdef("user_is_advanced")
507+
```
508+
509+
#### Tips for dynamic menu items
510+
511+
When using dynamic menu items:
512+
513+
1. **Use `reconsider: True`** to ensure the menu items are re-evaluated on each page
514+
2. **Avoid triggering undefined variables** by using functions like `showifdef()`, `defined()`, or `hasattr()` in your `hidden` conditions
515+
3. **Use `data from code` for complex logic** since labels need to be Python string expressions (hence the `|` and quotes)
516+
4. **Consider using `_internal.get('steps') < 2`** to hide items until the user has progressed past the first page
517+
518+
#### Example: Context-sensitive help menu
519+
520+
```yaml
521+
---
522+
reconsider: True
523+
variable name: al_menu_items_custom_items
524+
data from code:
525+
- url: |
526+
"https://example.com/general-help"
527+
label: |
528+
"General help"
529+
- url: |
530+
"https://example.com/income-help"
531+
label: |
532+
"Help with income questions"
533+
hidden: not showifdef("asking_about_income")
534+
- url: |
535+
url_action('save_progress')
536+
label: |
537+
"Save my progress"
538+
hidden: not user_logged_in() or (_internal.get('steps') < 2)
539+
```
540+
541+
By default, `al_menu_items_custom_items` is set to an empty list, so no custom menu items will appear unless you define them.
542+
460543
### `users` and `other_parties`
461544

462545
The variables `users` and `other_parties` can be used directly in your template,

0 commit comments

Comments
 (0)