Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: PAGES-224

...

The SPA front-end helper libraries provide APIs that can inform you through which you can stay informed about the status of the current renderer context of a an SPA page. The status An can be that your SPA page can be is running in:

  • A production environmentdeveloper mode.
  • The Pages editor.
  • Page The preview mode of the Pages editor.

Being aware of the current renderer context can be useful if you need to hit different URLs for content, do rendering or other things conditionally. The APIs provide context status functions for status information is retrievable in the Angular and React frameworks.  

In Angular

If you call the isDevMode() function, which is part of the @angular/core library, and the developer mode is enabled, you can see the status as a  comment in the DOM element.

To find out about the editor/preview statuswhether your SPA page is running in the Pages editor or in its page preview mode, inject the RendererContextService from the @magnolia/angular-renderer. You can then call the following functions to get the status:

Code Block
RendererContextService#inEditor() # Tell SPA is in editor or not

inEditorPreview() # Tell SPA is in editor and in preview mode

To get the current status of the dev mode, call the isDevMode() function that is part of the @angular/core library. If the dev mode is enabled, you can see the comment when inspect the DOM element when running in node dev server.

React

  • inEditor()
  • inEditorPreview()

In React

To retrieve the status in In React, make sure that you import {RendererContext} from the @magnolia/react-renderer and , and that the class of YourComponent extends the React.Component

After assigning static contextType = RendererContext you may can call the following functions to get the status:

...

  • this.context.

...

  • isDevMode
  • this.context.

...

  • inEditor
  • this.context.

...

  • inEditorPreview