Extending property model with data from external A...
# help-with-umbraco
g
I need to display a component on a page, that displays some data retrieved from an external API. The editor can set some configuration of the component in the Backoffice (number of results, sort order etc.) This data is then retireved from the API on each request. This component can be used on multiple different templates. How to tackle this? My first attempt was creating a custom property editor, where you set all the settings in the backend and then "enrich" the model in
ConvertIntermediateToObject
method of
PropertyValueConverter
on each request. I am not sure if this is the correct approach or not. The second approact that I took was to create an
Element Type
document type and added it as a property
Block list
in
Single block mode
. This is much easier in the Backoffice part, because I don't have to write all custom editor code by myself, but the issue here is that I don't know how to append API data to the model then. I tried to create new RenderController with the name of the Element Type document, but it is not triggered. Any help would be appreciated.
a
With those two options, I would go for the property editor and then build logic in the value converter. But I would also add some form of cache layer, as calling the API on each request is typically not ideal. Property value converters also support caching, which may or may not fit your case better. There may also be other options, but this will depend on your setup.
g
Would it be possible to use
PublishedContentWrapped
and
RenderController
or is this again usable only for actual document type with template? I was also looking at
ViewComponent
and
ViewModel
but it is the same problem as with the above.
a
If you're using Models Builder, you will have a generated model - let's say the class named FrontPage. You can then create a new FrontPageViewModel class that extends the FrontPage class, and than add the extra property to the view model class. Then in your RenderController, you can handle when the front page it requested, and return a FrontPageViewModel instead of the FrontPage model.
g
But I cannot reuse FrontPageViewModel in other templates, right? For now I think that I will try with
ViewComponent
. This way I can avoid building complex Backoffice UI.
a
> But I cannot reuse FrontPageViewModel in other templates, right? Probably not. Again it depends on what you're doing. > For now I think that I will try with ViewComponent. This way I can avoid building complex Backoffice UI That should also do the trick 😉
m
not sure if this helps. For reuse across templates we sometimes go with compositions and
Copy code
csharp
if ( {SomeIPublishedContent} as IExtendedComposition is IExtendedComposition extComp) 
{
 var prop = extComp.STRONGLYTYPEDPROP
}
but I'd probably go for the
ViewComponent
for your use case.
3 Views