0

I have created a custom web api which converts glass object to json string. The glass object involves rich text field where internal links can be used. The link is fully rendered to absolute path in the response if not logged-in to sitecore but if logged-in to sitecore the dynamic sitecore link from the rich text html is returned. I know this is the expected behavior in sitecore but I'm wondering if there is any way force the field to pass through the rendering pipeline always.

I create glass sitecore context in api controller to access the item

new SitecoreContext(Context.Database)
0

You can force the current request to be served in Normal mode by setting the display mode in your code:

Sitecore.Context.Site.SetDisplayMode(Sitecore.Sites.DisplayMode.Normal, Sitecore.Sites.DisplayModeDuration.ResetAfterRequest);

Glass uses the Sitecore.Context.PageMode internally, forcing the mode to normal will cause Glass to use it's own internal data mappers rather than using Sitecore's Renderfield pipelines.

  • Thanks @jammykam it worked. I believe this only sets the display mode for the current request and resets it back. – Bevin Oct 3 '17 at 23:46
  • Yes, the second parameter is sets the DisplayModeDuration. Valid values are Remember, Temporary or ResetAfterRequest. I believe it resets it back but please try Temporary if you have issues. – jammykam Oct 4 '17 at 0:22
  • I had issues with experience editor and preview when i used ResetAfterRequest, I had to set the Display mode back to the original state once my glass elements are formed. Thanks! – Bevin Oct 10 '17 at 3:17
  • Did you try setting it to Temporary? That should mean the display mode cookie is not changed. – jammykam Oct 10 '17 at 11:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.