Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • sam how 29 posts 129 karma points
    Nov 20, 2024 @ 12:49
    sam how
    0

    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

  • Afreed 54 posts 261 karma points
    Nov 21, 2024 @ 05:17
    Afreed
    100

    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!

  • sam how 29 posts 129 karma points
    Nov 21, 2024 @ 05:36
    sam how
    0

    Thank you Afreed for you response. Do I need to create a controller for the custom view to do this?

  • Afreed 54 posts 261 karma points
    Nov 21, 2024 @ 06:16
    Afreed
    0

    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

  • sam how 29 posts 129 karma points
    Nov 21, 2024 @ 08:51
    sam how
    0

    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.

    enter image description here

  • Afreed 54 posts 261 karma points
    Nov 21, 2024 @ 09:31
    Afreed
    0

    Hope this helps you understand a bit more:

       <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
          });
        });
      };
    });
    
  • sam how 29 posts 129 karma points
    29 days ago
    sam how
    0

    Thanks Afreed. The best!

Please Sign in or register to post replies

Write your reply to:

Draft