This page explains how you can integrate your play application with the play-cms. Each method has its advantages and disadvantages.
Pro: You can use full power of play's mvc and routing mechanisms
Con: Many cms features such as modifying the virtual path or automatic inclusion in search are not available
Choose this if you need the full power of play's controllers and routing.
You can share the main layout template(s) between cms and non-cms pages. For this, you use the Page interface as parameter in your main template. The CMS' PageBlock implements Page, and in non-cms pages you instantiate a StandalonePage object, which contains general page info like title, description, and alternate language urls.
The language urls are optional and will enable language switching on non-cms-pages just like for cms pages. If you skip this, the default language selector will point to the selected language's homepage instead.
Example:
ProductController.java:
StandalonePage page = new StandalonePage("product.list.page.title", "product.list.page.description")
.addAlternateLanguageUrl("en", "/products")
.addAlternateLanguageUrl("de", "/produkte");
return ok(productList.render(products, page));
productList.scala.html:
@(products: List[product], page: ch.insign.cms.models.StandalonePage)
@import ch.insign.cms.models.StandalonePage
@main(page) {
... your template code ...
}
You can add your application pages to the cms navigation by adding a LinkBlock to the navigation tree. Just like adding a cms page, but it will only link to your application page. The admin still can name, and translate the link text, move it around etc.
Important: The LinkBlock has the usual permissions and time-control settings, but this only covers the navigation entry: Your application page is cms-independent, you need to protect access yourself.
The output of cms pages is passed through the filter framework, which allows processing/modifying content. Most notably, this is used for processing <a> tag href targets (internally they're stored with a pointer to the target page, e.g. <a >
. The filter will convert them to a valid tag on output).
To process your non-cms page's content by the cms filter framework, use this in your controllers:
return ok(CMS.getFilterManager().processOutput(views.html.mytemplate.render(), null));
Pro: All cms features like search indexing, permission/time controls etc. will work. The admin can create multiple page instances and configure them through your block edit template.
Con: You cannot use Play's controllers and routes
Choose this if your application does not require extensive interaction through different routes or if the interaction is done by ajax. Or if the admin should be able to create multiple pages with different settings.
Html render()
and return the page's contentHtml editForm(Form editForm)
and return the page's edit form (optional)boolean isSearchable()
(or use setSearchable()
) to set whether your page should appear in the search indexResult routeRequest(NavigationItem navItem)
, but at the expense of some cms features (not recommended).Creating a cms block instead of a cms page means you / the admins can and and place your application content blocks freely, multiple times, on every page (that is configured to take this block type as subcontent), like other cms blocks. Technically, do the same steps as described above.
Hint: You can configure which blocks can be added where:
To use cms-managed content into your application, simply use the cms' API to get the desired object and its content. It's suggested to use a key to identify them.
Example from code:
AbstractBlock.find.byKey("someKey").render();
Note: This method will create an empty block if no block with this key exists.