Best approach to passing a parameter to an inherited view

I have a “child” project which inherits a view from a “parent” project. For this view to function, it needs to know which tag provider to use; so we have defined a “tagProvider” parameter. The question is, what is the best way for a “child” project to pass along a parameter to an inherited view? Looking at the Page Configuration, something like “/base-page/:tagProvider” might work, but I’d actually like to be able to set the param value inline, e.g.: “/base-page/?tagProvider=my_tag_provider”, as this value will not change within the child project.

Appreciate any thoughts.

There’s some mixed terminology in use here because you’re asking about View parameters but using a Page Configuration.

  • If you’re using any “Embedding” component, you want to specify the param value within the component.
  • If you’re navigating to a page via a URL, then you do want to use /base-page/:my_tag_provider.
  • If this parameter is never going to change within a project, then you’re better off removing the parameter of the View altogether and instead binding to either the result of a database query (where the query obtains the provider based off of the project name), or a session property which contains the provider for the project.

It’s actually the 2nd bullet point - we’re navigating to the page. In your last bullet point, you mention using the project name and executing a query. Is project name the same as page.props.title? If so, this is what we’re currently doing, so maybe we’re not too far off.

No, page.props.title defaults to the project name, but there's no guarantee that page.props.title will always have the name of the project as you could write anything you want to that property. If you decide to use a query, you'd want to have a Named Query in the parent project along the lines of

select tagProvider from providers where projectName="MyProjectName"

Then, in each child project you would override the Named Query and provide the name of the project. You're then on the hook for maintaining a database table with project-provider relations.

Got it. Just curious. Is there a property, similar to page.props.title, which exposes the current project name? I’ve seen system.util.getProjectName() but would prefer a prop, if it exists. Thanks.

There is not a session property, but the project name can be obtained through scripting. If you need the project name for something like this, I would set a custom property on session startup (in the Designer menu bar: Project > Session Events > Startup).

for ses in system.perspective.getSessionInfo():
    if ses.id == session.props.id:
        self.custom.projectName = ses.project

Interesting. I wasn’t aware of getSessionInfo().

While I realize this is going a bit beyond just the passing of parameters, can you provide thoughts on the following general approach for maintaining projects?

Database:

  • Add a table - project, with columns (id, name, description, tag_provider, etc…)

Base Project:

  • Add a custom session property - projectId
  • Using projectId, the Base Project could internally look up any needed project-specific info, such as tag_provider, from the project table.

Child Project

  • Add a custom session property - projectId (to override the base projectId property)

Usage would be to enter a row into the project table, then use that id to set the projectId property within the Child Project > Base Project.

It seems like this would solve the original ask as well as offer a great deal of flexibility.

Appreciate your thoughts.

While I offered the DB solution, I advise against setting up a database just to maintain project information.

The proposed setup only gets you the capability to define a different Tag Provider for each project which you could easily do with just a custom session property within each project, without the added cost of maintaining your database. Your entire DB approach could be done with just having session.custom.project_tag_provider set within each project.