Home

Awesome

Build Status

Hello Pagelets!

just a few minutes and you have a complete Play application based on the Play Pagelets Module running.

See the app in action: Pagelets on Heroku *note that it runs on a free dyno which takes a couple of seconds to wake up.

TL;DR

The demo application serves the purpose to

What is a Pagelet

A pagelet is a small independent unit which consists of view, controller action and optionally a service which obtains the data to be rendered. Usually a web page is composed of multiple pagelets.

The demo app

This demo application shows how a modular and resilient web application can be built using the Playframework 2 and the Play Pagelets Module.

This example app is a small multi-language website. The page is composed of multiple pagelets. Each pagelet is completely independent and obtains data from a remote service and renders the data by means of a standard twirl template.

Depending on the selected language, the home page is composed from different pagelets. This shows how the page composition can be manipulated at runtime based on the properties of an incoming request.

The demo also invites to to simulate failure by configuring remote services to time-out or serve broken data.

To get a rough idea what the pagelet API looks like:

A page configuration

def tree(r: RequestHeader) = 
  Tree("root".id, Seq(
    Leaf("header".id, () => header).withJavascript(Javascript("lib/bootstrap/js/dropdown.min.js")),
    Tree("content".id, Seq(
      Leaf("carousel".id, () => carousel).withFallback(fallback("Carousel") _),
      Leaf("text".id, () => text).withFallback(fallback("Text") _)
    )),
    Leaf("footer".id, () => footer).withCss(Css("stylesheets/footer.min.css"))
  ))

A main action to render a complete page

def index = PageAction.async(routes.HomeController.errorPage)(_ => "Page Title", tree) { (request, page) =>
  views.html.wrapper(routes.HomeController.resourceFor)(page)
}

A pagelet (just a standard Play action)

def carousel = Action.async { implicit request =>
  carouselService.carousel.map { teasers =>
    Ok(views.html.pagelets.carousel(teasers))
  }
}

A fallback pagelet (also just a standard Play action)

def fallback(name: String)() = Action {
  Ok(views.html.pagelets.fallback(name))
}

Getting started

Open a terminal and clone the github repository with

git clone git@github.com:splink/pagelets-seed.git
cd play-pagelets-seed
sbt run

then point your browser to http://localhost:9000

If you are interested in more details, check out the main Play Pagelets repository