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 25 posts 115 karma points
    22 hours ago
    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 33 posts 158 karma points
    6 hours ago
    Afreed
    0

    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 25 posts 115 karma points
    5 hours ago
    sam how
    0

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

  • Afreed 33 posts 158 karma points
    5 hours ago
    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 25 posts 115 karma points
    2 hours ago
    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 33 posts 158 karma points
    1 hour ago
    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
          });
        });
      };
    });
    
Please Sign in or register to post replies

Write your reply to:

Draft