Web Master Page

I created (what I like to call a “Master Web Page”), which has all of the controls and key functionality on that page. I was hoping that if I created other web pages which inherited from that “master”, those pages would also inherit the controls, functionality, and images, etc., but for some reason, that doesn’t seem to be the case.

Am I missing a key step?

I think what you might want are containers https://documentation.xojo.com/api/user_interface/web/webcontainer.html

Yep. I’ve been using containers and they do work well. I was just hoping to create the layout on a single web page and as such all other pages that inherit from it would use it as the template.

Containers aren’t a problem, so I’ll stick to using them.

Thanks!

Yes master pages do come in very handy but nothing like that built into xojo web currently.

with Xojo you build web apps, not web sites.

Even web apps could benefit from this capability. I spend time up front with my web apps to create a layout.

Many of my customers want the web apps that I build for them to take on the visual characteristics of either their intranet site or website such that the end users see it as simply another page within their intranet site or website. Containers have helped with this for sure.

However with master page capability, I can drag the container(s) and other controls onto the master and all webpages that inherit from it would also have those controls.

I was just asking if it were possible in Xojo because I’ve built many web apps in ASP.NET that use master pages, which is what made me think of it in the first place.

I’ve also used them in the past to implement the following:

  • Dynamic Title and Meta Tags: Content pages can easily override the Master Page’s elements (like page titles or dynamic SEO meta tags) programmatically.
  • Master Page Property Access: Content pages can also access properties and/or public methods on the Master Page, allowing you to dynamically toggle elements (like showing/hiding a banner based on the user’s role) and so forth and so on.

I appreciate the feedback. Containers are fine.

Basically you’re talking about templating, right? You can do this by building your page with your header/footer/sidebar then programmatically embed WebContainers depending upon what needs to be displayed. Couple this with Session.URL* and you can determine what users want to view. Something like this in WebPage.Opening:

Sub Opening() Handles Opening
  if Session.URLParameterCount > 0 then
    select case Session.URLParameter( "action" )
    case "viewCustomer"
      '// Embed your readonly "View" container
    case "newCustomer"
      '// Embed a container for adding a new record
    case "editCustomer"
      '// Embed a container for editing records
    case "viewEquipment"
      '// Embed your readonly "View" container
    case "newEquipment"
      '// Embed a container for adding a new record
      ...
    end select
  end if
End Sub

Then structure your URLs using appropriate query strings:

https://mysite.com/myapp/?action=editCustomer&id=12345

SEO is a bit of different beast in Xojo Web. This might be a worthwhile read for you. Or you can add specific metadata such as keywords to the App.HTMLHeader property.

As for property access, this is easily achieved by ensuring that the ImplicitInstance property of your Master Page is set to true. Then you can acces its public properties, methods, controls, constants, etc. by referencing it by name:

myMasterPage.Title = "Cool Master Page"
' -- OR --
myMasterPage.Label1.Text = "Some Text"

Here’s a more complete example of the container embedding in the WebPage.Opening event handler:

Sub Opening() Handles Opening  
  var embedContainer as WebContainer
  if Session.URLParameterCount > 0 then
    select case Session.URLParameter( "page" )
    case "one"
      embedContainer = new Container1
    case "two"
      embedContainer = new Container2
    end select
  end if
  
  if embedContainer is nil then embedContainer = new ContainerHomeDashboard

  embedContainer.LockLeft = True
  embedContainer.LockRight = True
  embedContainer.LockTop = True
  embedContainer.LockBottom = True
  embedContainer.EmbedWithin( self, 0, 100, self.Width, self.Height - 200 )
End Sub

Of course you can move this code to a method and track the current container using a property, and switch them out as needed by closing the old container and add the new one then storing its reference in the property. Then your in-app navigation and URL-based navigation are unified.

This is helpful. I’ll review what you’ve posted. Yes! SEO is a different beast altogether.

If you have any other questions about the container embedding master page, just ask. I’ve implemented this a number of different ways in many apps over the years. For what you need, this is the path I recommend.

Hey, Thanks!

Some of the web apps that I build for larger companies who have strict branding policies have been a pain because they have guidelines on placement and padding for everything on the page. The last web app my team and I built (using asp.net) had well over 30 different pages (it was a sizable application).

The Master page feature in asp.net saved us a ton of time because once their corporate compliance and branding standards team approved the entire layout of the master page, we simply built the content pages which inherited from the master.

So help me, I swear I must have spent more time sitting in conference rooms with that corp compliance team over a period of two weeks than the team and I actually spent building the software.

They dang-near pulled out rulers to measure padding and element sizes, colors, fonts, etc.

We used asp.net containers on the Master, which saved a ton of time as well.

This is where master page templates and containers are a saving grace.

So help me, I swear I must have spent more time sitting in conference rooms with that corp compliance team over a period of two weeks than the team and I actually spent building the software.

I’ve definitely been there. More meetings than lines of code written.

This is where master page templates and containers are a saving grace.

Without a doubt. I also prefer the container approach myself as it feels like templating in PHP and other languages. Build parts that get put together at runtime for a consistent experience rather than worrying about accidentally moving a control on one of the pages out of 30. Likewise, refactoring for branding changes is much simpler, should that arise.