2 - Get a Document

Previous - Code DiffNext

Reset the workspace to step 2:

git checkout -f step-2

This steps adds a link to each document in the list, linking to a page rendering some of the document's content.

The Document Detail Resource

As you have seen in the previous step the content of a particular document can be accessed by appending that document's ID to the Document Detail resource's URL:


For example:


The response consists of a JSON object containing a number of meta properties as well as the properties holding the actual content (as defined by the document's type). The example below shows a document breakfast of type myproject:eventsdocument. Some of its content properties include a title, a date, an end date, a location, an introduction and some rich text content.

      "myproject:location":"Room 101",
      "myproject:introduction":"Start the day with a nice breakfast.",
         "content":"<p>Breakfast is served starting from 8:00 until 9:30.</p>"

Note that the document's type, as well as the document's actual content properties, are namespaced. Namespaces prevent different document types from having naming conflicts. When referring to a document type or a document property in Bloomreach Experience Manager it must always be prepended by its namespace's prefix and a colon, e.g. myproject:eventsdocument or myproject:title.

Also note that the rich text content (items['myproject:content'].content) consists of an HTML string.

Code Changes


A dependency to ngSanatize is added to the app in order to be able to sanitize (i.e. strip any dangerous or unwanted tokens from) the HTML content.


    <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.8/angular-sanitize.js"></script>


var contentRestApp = angular.module('contentRestApp', [ 'ngRoute', 'ngResource',
    'ngSanitize' ]);


The DocumentsService is extended with a getDocumentById function which uses the $resource service to retrieve the content for a particular document from the Document Detail resource as explained above.


contentRestApp.factory('DocumentsService', function($resource, apiPrefix) {
  return {
    getList : function() {
      return $resource(apiPrefix + 'documents/', {}).get();
    getDocumentById : function(uuid) {
      return $resource(apiPrefix + 'documents/' + uuid).get();


The DocumentsController is extended so it retrieves either the documents list or an individual document's content, depending on the routing parameters. The responses are added to the scope so the views can render the content.


contentRestApp.controller('DocumentsController', function($scope, $routeParams,
    DocumentsService, apiPrefix) {

  if (!$routeParams.uuid) {
    DocumentsService.getList().$promise.then(function(response) {
      $scope.documents = response;
  } else {
        response) {
      $scope.document = response;


Views and Routing

A new detail view is added which renders a document's title, introduction and rich text content (the News, Event and Simple Content document types have these properties in common). The rich text content is inserted into the view using the ngBindHtml directive so it is automatically sanitized.

Routing is added to map the new detail view to URLs using the uuid routing parameter.

Finally, links to the detail view are added to the list items in the documents-list view.


  <div ng-bind-html="document.items['myproject:content'].content"></div>


contentRestApp.config(function($routeProvider) {
  $routeProvider.when('/', {
    templateUrl : 'document-list.html',
    controller : 'DocumentsController'
  }).when('/:uuid', {
    templateUrl : 'detail.html',
    controller : 'DocumentsController'



  <li ng-repeat="document in documents.items"><a


  • Use Bloomreach Experience Manager to edit one of the documents and create a link to another document inside the rich text field. Check if the link works in the app. It doesn't because Bloomreach Experience Manager is unaware of what frontend application might render the content, it is therefore up to the frontend application to resolve internal links in the content. This will be done in the next step.


In this step the app was extended with pages rendering individual document's content. Now go to step 3 to learn how to handle links between documents.

Previous - Code DiffNext

Did you find this page helpful?
How could this documentation serve you better?
On this page
    Did you find this page helpful?
    How could this documentation serve you better?