Page ID Trouble

I am having a little trouble and I was hoping someone might have some insight.

I am trying to set the display property based on which pageID is found in the session information. I have tried a lot of different property and configurations. I literally have a text box for each of the session.page.props.pageid, path, and primaryView but, I am not able to make the script roll through the containers correctly.

Here is the snippet I am using. Any help would be GREATLY appreciated:

def enable_active_page_bar(self):

try:
    system.util.getLogger("NavBar").info("Starting enable_active_page_bar function")
    
    # Check if self exists and has necessary attributes
    if self is None:
        system.util.getLogger("NavBar").error("self is None")
        return
    
    if not hasattr(self, 'page'):
        system.util.getLogger("NavBar").error("self has no 'page' attribute")
        return
    
    if self.page is None:
        system.util.getLogger("NavBar").error("self.page is None")
        return
    
    # Get the current page path
    current_page = self.page.props.path
    system.util.getLogger("NavBar").info("Current page path: %s" % current_page)
    
    # Define a dictionary mapping pages to container indices
    page_to_container = {   
        '/OverviewTest1': 0,
        '/Dashboard': 0,
        '/OverviewTest2': 1,
        '/Details': 1,
        '/Schedule': 2,
        '/Tasks': 2,
        '/Users': 3,
        '/Settings': 3
    }
    
    # Set the active container based on the current page
    active_index = page_to_container.get(current_page, 0)  # Default to 0 if not found
    system.util.getLogger("NavBar").info("Active index: %d" % active_index)
    
    # Check if self has a PH child
    ph = self.getChild("PH")
    if ph is None:
        system.util.getLogger("NavBar").error("PH container not found")
        return
    
    # Update the display property for each container
    for i in range(1, 5):
        container_name = 'PH_{}'.format(i)
        try:
            container = self.getChild("PH").getChild(container_name) 
            if container:
                if hasattr(container.props, 'style'):
                    container.position.display = (i - 1 == active_index)
                    system.util.getLogger("NavBar").info("Set display for %s to %s" % (container_name, str(i - 1 == active_index)))
                else:
                    system.util.getLogger("NavBar").warn("Container %s has no style property" % container_name)
            else:
                system.util.getLogger("NavBar").warn("Container %s not found" % container_name)
        except Exception as e:
            system.util.getLogger("NavBar").error("Error setting display for %s: %s" % (container_name, str(e)))
    
    # Check if self has a session property
    if not hasattr(self, 'session') or self.session is None:
        system.util.getLogger("NavBar").error("self.session is None")
        return
    
    # Store the current active container index in a session prop for later use
    self.session.props.activeNavContainerIndex = active_index
    system.util.getLogger("NavBar").info("Session prop set: %d" % self.session.props.activeNavContainerIndex)
    
except Exception as e:
    system.util.getLogger("NavBar").error("Unexpected error in enable_active_page_bar: %s" % str(e))
    import traceback
    system.util.getLogger("NavBar").error(traceback.format_exc())

To make sure I understand you are binding to the display property of say a flex container?

If you are just wanting to display different containers based on what path you are at I would just use an expression binding like this:
{page.props.path} = "/OverviewTest1" || {page.props.path} = "/Dashboard"

A question I do have is why..If you are navigating to different pages wouldn't you have different views? Are you using the exact same view for each page?

I have a nav bar view that I am embedding into my other main views. In an effort to minimalize the display, I wanted to show the "relevant" navbar for the page category.

So "qa" views would have the qa navbar container visible. The "production" pages would be the production relevant navbar container.

I also have a toggle already, that allows the containers to toggle through so you can select which navbar category you want, but that is a little less intuitive than "defaulting" the nav category based on page genre.

In your example, I would just bind the position.display property to the page.props.path inthe simple expression lang?

This is job for a docked view. If you insist on embedding, you should just have the parent view pass a parameter to configure that nav view.

1 Like

Thank you for the help!