/// Monday, November 28

Gamba: Branding

Gamba, the Boo MVC2/Rails framework is coming along nicely. As I add features to Gamba I'll write a short article explaining the usefulness of the feature. This article focuses on branding, the ability for a multi-user website to appear and behave differently based on the user.


A very simple type of branding is achieved by most blog hosts. They allow users to specify a different template for their personal blog. For enterprise websites branding requires more than a new 'skin'. Sub applications of an enterprise-level web application may access a different database or perform specific business logic tailored for the client.


In this example, we'll create a simple web app which changes behavior based on the brand's URL. Since Gamba is an MVC2 framework, pages are not directly accessible as they are in ASP.NET. Don't let this dissuade you. Creating a view is as easy as deriving from DefaultController and a template for each view.

// Foo.boo - controller
class Foo(DefaultController):
    def Hello():
        ViewMethod = HelloView

    def Name():
        Model["name"] = "mario"
        ViewMethod = NameView
// Hello.HelloView.tpl - template for HelloView
<p>Hello world!</p>
// Hello.NameView.tpl - template for NameView
<p>Hello ${Model['name']}</p>

Gamba's IController has many views whereas an ASP.NET page has one view, the .aspx page itself. Gamba may choose not to call any views of a controller if, for example, the user has not logged in. To view the views, compile the class above and drop the assembly into Gamba's bin folder, then browse:

Let's do something different for any user of the boo sub application. A sub application is accessed via a different URL prefix - http:://localhost:8080/gamba/boo. Gamba will automatically reuse the controller above if we don't do any modifications. Let's create a new layout and also create a controller for the boo sub application. The layout is basic, we'll just change the background to green. I don't use a template here just to show you don't have to use templates at all:

class BooLayout(DefaultLayout):
    override def Execute() as List:
        htmlTop = "<html><head></head><body bgcolor='green'>"
        htmlBottom = "</body></html>"

        return [htmlTop, _child.ViewMethod(), htmlBottom]

Let's assume Foo has a lot of functionality in it and we want to modify one view. Using OOP derive a controller from Foo.

class Bar(Foo):
    override def Name():
        Model['names'] = ['mgutz', 'bamboo', 'ckknight']
        ViewMethod = NamesView
# Bar.NamesView.tpl - template for NamesView
<% for name in Model['names']: %>
<p>Hello ${name}</p>

<% end %>

Again, compile the classes and drop into Gamba's bin folder. Browse the two pages noting the use of 'boo/bar':


This article described how Gamba solves one of the challenges facing web developers, branding. In particular, Gamba uses object-oriented programming to alter behaviour and appearance unlike some other frameworks which resort to using a template hierarchy.

BTW, as someone commented, I use FireFox. I used IE so I could capture the address bar in a small window.


A professionally crafted professional logo design is one of the greatest blessings for a company; whether it is big or small. It gives them an identity of their own and makes them different from others.
Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?