First Experience With BrowserCMS

I had a chance to try BrowserCMS for several days. BrowserCMS is light CMS which can be plugged into existing rails application.

One thing that we usually do when testing new CMS is trying its extensibility. BrowserCMS uses “content block” term for its content type. So lets say we create new content block named “NewsItem”. Once we create content block, we can also handle its admin editor. To make a content block visible to public, we will need to create “portlet”. A portlet basically is a widget showing data from content blocks.

Continuing our previous scenario, we can create “Recent news” portlet which shows the latest published news and we also need to create portlet which shows the news detail itself. When user click the news item in Recent News, then he will be redirected to News detail page which contains “news detail” portlet.

One problem that I encountered was how to create News detail page which has pretty url (like, /news/12/fowler-on-software-design), instead of ( /news/detail?id=12&slug=fowler-on-software-design). Obviously for normal rails application we just need to change config/routes.rb however we’re integrating with BrowserCMS.

The documentation doesn’t specify how to solve this common issue. Fortunately there is Google Group’s discussion which showed me the answer

Apparently to achieve that purpose, we need to create page itself manually by code, and set its page routes to our defined patterns. I will illustrate it with my rake task which is responsible to create page route.

namespace :setup do
    task :news_route =>:environment do

        news_page = Cms::Page.create!(:name => "News Detail",
            :path => "/news/detail",
            :template_file_name => "default.html.erb" ,
            :parent => Cms::Section.root.first
        )
        NewsDetailPortlet.create!(:name => "News Detail Portlet",
            :template => NewsDetailPortlet.default_template,
            :connect_to_page_id => news_page.id,
            :connect_to_container => "main"
        )

        route = news_page.page_routes.build(
            :name => "News Detail",
            :pattern => "/news/:id/:slug",
            :code => "@news = News.with_id(params[:id])"
        )
        route.add_condition(:method, "get")
        route.add_requirement(:id, '\d')
        route.add_requirement(:slug, '[a-z0-9\-]{3,}')
        route.save!
    end
end

What the above task done are:

  • Create new page record in database, and specify its section (important)

  • Create new portlet and set up its position

  • Create new page route from newly created page