Hi Peter,
It’s probably simplest to have all the possible menu items on your form, and then set the visible
property to True
or False
to show and hide them.
That said, here’s a more advanced guide to controlling HTML-templated forms like the Dashboard:
If you add a component directly to a templated form like the Dashboard (rather than adding to a panel on the page), you’ll see the add_component()
method has an optional keyword parameter called slot
. This lets you name where in the page your component will land. Eg:
google_link = Link(url="https://google.com", text="Visit Google")
self.add_component(google_link, slot='sidebar')
In the Dashboard layout, specifying the sidebar
slot will put the component in the side navigation. Specifying nav-right
will place it in the top-right navigation bar. Here’s a more involved example:
logout_link = Link(text="Log out", icon="fa:sign-out")
def do_logout(**e):
anvil.users.logout()
open_form('LoggedOut')
logout_link.set_event_handler('click', do_logout)
self.add_component(logout_link, slot='nav-right')
You can explore the slots yourself by dropping components in various points on the page, and then looking in their “Container properties” for their slot
value.
For more information about how Anvil’s HTML templating slots work, and how to create your own, you can check our reference documentation.
Hope that helps!
(Looks like you decided to go with showing/hiding options. I’d agree that sounds like the best choice for you, but hopefully this guide could prove useful to someone else )