SPEAK

Integrate SPEAK 3 applications with Sitecore

Abstract

How to integrate SPEAK 3 Angular applications with Sitecore

SPEAK 3 applications are Angular applications. They can run independently of Sitecore. However, the purpose of SPEAK 3 is to make it simple to integrate Sitecore-branded Angular applications with a Sitecore CM (content management) server and the Sitecore user interface.

The Sitecore integration affects several areas. The topics that describe these areas are listed here.

This topic describes how to set up a development environment so you can use the SPEAK 3 Sitecore integration features.

The NgScModule Angular module includes the following Sitecore integration features:

  • Sitecore context

  • Translations for applications

  • Translations for the SPEAK 3 component library

  • Component user access authorization

  • Preventing cross-site request forgery (Anti-CSRF)

You do not have to import the feature modules yourself.

Dependencies

The NgScModule module has a dependency on ngx-translate, which SPEAK 3 makes available for translations in applications. To make it easier to set up, the NgScModule module configures and exports ngx-translate.

Configuration

Follow these steps to configure the Sitecore integration:

  1. Configure the module:

    // imports
    
    import { NgScModule } from '@speak/ng-sc';
    import { CONTEXT, DICTIONARY } from '@speak/ng-bcl';
    
    // App module imports
    
    @NgModule({
       imports: [
           NgScModule.forRoot({
            contextToken: CONTEXT, // Provide Sitecore context for SPEAK 3 Components (optional)
            dictionaryToken: DICTIONARY, // Provide translations for SPEAK 3 Components (optional)
           translateItemId: '0C979B7C-077E-4E99-9B15-B49592405891', // ItemId where your application stores translation items (optional)
           authItemId: '1BC79B7C-012E-4E9C-9B15-B4959B123653' // ItemId where your application stores user access authorization (optional)
           })
          ],
    
       declarations: [AppComponent],
       bootstrap: [AppComponent]
    })
    
    export class AppModule { }
              

    Note

    You must change the items IDs for translateItemId and authItemId to the actual values in your Sitecore instance.

  2. Initialize NgScService when your application initializes:

    // app.component.ts
    
    import { Component, OnInit } from '@angular/core';
    import { NgScService } from '@speak/ng-sc';
    
    @Component({
        selector: 'app-root',
        templateUrl: './app.component.html',
        styleUrls: ['./app.component.css']
    })
    
    export class AppComponent implements OnInit {
    
    constructor(
        private ngScService: NgScService
    ) {}
        ngOnInit() {
        this.ngScService.init();
        }
    }