How do I render a content picker blocklist in a custom view in the backoffice?
I have a blocklist, and within it, there is a block containing a content picker data type. This content picker selects an articles page that contains 4 child articles. I want to create a custom view in the backoffice, but I am unsure how to render the content picker and the 4 selected child articles in the custom view. I am using umbraco 13
If you're comfortable with custom views, you can grab the block data using {{block.data}}. For the content picker, you’ll want to use entityResource.getByIds(ids, entityType) to fetch the data.
Make sure:
For a content picker, the entityType should be "Document".
Example id: umb://document/c63a077242624f72b69e29247ffccf6a.
This will give you the details of the picked node. To get the child articles, you can then use something like contentResource.getChildren(id).
Yes, you’ll need a custom AngularJS controller for your custom view to handle fetching and rendering the data. In the controller, you can use entityResource.getByIds() to fetch the content picker data and contentResource.getChildren() to grab the child articles. Then, you can bind this data to the scope for displaying it in the view.
Hello Afreed
I tried to create a AngularJS controller. I was able to retrieved the content picker node ids using entityResource.getByIds but I'm I get this error message.
<div class="skeleton-wrap image-only" ng-controller="ContentSliderController">
<button ng-click="fetchContent()">Fetch Content Picker Data</button>
<!-- Display fetched content -->
<div ng-if="fetchedData.length">
<h3>Fetched Content:</h3>
<ul>
<li ng-repeat="item in fetchedData">{{ item.variants[0].name }}</li>
</ul>
</div>
</div>
angular.module("umbraco").controller("ContentSliderController", function ($scope, contentResource) {
// Function to fetch data using the contentResource
$scope.fetchContent = function () {
const udiList = $scope.block.data.listingParentNodePicker.split(","); // Split UDIs into an array
$scope.fetchedData = []; // Initialize an array to store fetched content
// Loop through each UDI and fetch content
udiList.forEach(function (udi) {
contentResource.getById(udi.trim()).then(function (response) {
$scope.fetchedData.push(response); // Add the fetched content to the array
});
});
};
});
How do I render a content picker blocklist in a custom view in the backoffice?
I have a blocklist, and within it, there is a block containing a content picker data type. This content picker selects an articles page that contains 4 child articles. I want to create a custom view in the backoffice, but I am unsure how to render the content picker and the 4 selected child articles in the custom view. I am using umbraco 13
Hi Sam,
If you're comfortable with custom views, you can grab the block data using {{block.data}}. For the content picker, you’ll want to use entityResource.getByIds(ids, entityType) to fetch the data.
Make sure:
For a content picker, the entityType should be "Document". Example id: umb://document/c63a077242624f72b69e29247ffccf6a. This will give you the details of the picked node. To get the child articles, you can then use something like contentResource.getChildren(id).
Hope this helps!
Thank you Afreed for you response. Do I need to create a controller for the custom view to do this?
Yes, you’ll need a custom AngularJS controller for your custom view to handle fetching and rendering the data. In the controller, you can use entityResource.getByIds() to fetch the content picker data and contentResource.getChildren() to grab the child articles. Then, you can bind this data to the scope for displaying it in the view.
you can follow the steps here Build a Custom View for a Block
Hello Afreed I tried to create a AngularJS controller. I was able to retrieved the content picker node ids using entityResource.getByIds but I'm I get this error message.
Hope this helps you understand a bit more:
is working on a reply...