Is there a way to reference attributes from another page or even the layout?

What I’m trying to do:
I have 3 pages under a “master” layout. Just wondering if it’s possible to reference some of the self.items dicts when the master layout initializes?

For example:
MasterReact has:

self.item = {
      'logged_in_user': anvil.users.get_user(),
      'log_description': f"Account Log Out: {anvil.users.get_user()['email']}" if anvil.users.get_user() else "Log In"
    }

I’d like to reference these items in a page that uses this master layout.

What I’ve tried and what’s not working:
Doesn’t seem like the classes in the webpage are inheriting from the the master template so can’t reference it.

Clone link:
share a copy of your app

If I understood what you want, you can use:

In the page that uses the layout

self.layout.item['logged_in_user']

Or you can use different attributes.

In the MainLayout:

...
@property
def logged_in_user(self):
    #It would be best to save this in a local private attribute instead of just returning:
    return anvil.users.get_user() 

In the Page that uses the layout:

self.layout.logged_in_user
4 Likes

I see! self.layout is the way to get access to my layout class!
Thank you.