Skip to content

An activator seed template and demo application to illustrate the Pagelets Module for the Play Framework

License

Notifications You must be signed in to change notification settings

splink/pagelets-seed

Repository files navigation

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

  • showcase the Play Pagelets Module and it's advantages
  • demonstrate how to build a pagelet based application
  • serve as a template for pagelet based projects

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
  • then enter
cd play-pagelets-seed
  • then enter
sbt run

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

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

About

An activator seed template and demo application to illustrate the Pagelets Module for the Play Framework

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published