Closed ScarlettCode closed 3 years ago
You can inject anything into your IPageBlockTypeDisplayModelMapper
and call anything in MapAsync
, so yes you can call out to a service or run a custom database call. Some things to consider:
For accessing user state:
IExecutionContext
parameter as part of the IUserContext
object.For anything else, you can access user data though IContentRepository
e.g.
var user = _contentRepository
.Users()
.GetCurrent()
.AsSummary()
.ExecuteAsync();
Or inject IUserContextService
and use that to get basic user data such as the id and go from there.
Hi,
I'm looking for some guidance in what would be the best way to integrate external data into the CMS. I have some external data and I want to create "widgets" which can then be placed anywhere on any page. My current thought is to use Page Block Types. My question is can I call out to a third party api or another database from within the MapAsync method of the IPageBlockTypeDisplayModelMapper or is there a better way of doing this?
Then following on for this, if a "Widget" was user specific can I access a users logged in state and id from within the MapAsync method so I can use that to fetch the correct data for a specific user?
Thanks