Copied to clipboard

Flag this post as spam?

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


  • Neil 37 posts 201 karma points
    Feb 21, 2022 @ 15:32
    Neil
    0

    UmbracoHelper in BackOffice Property Editor

    I'm creating a custom property editor, and I am trying to get hold of a list of all content of a particular type, to populate a dropdown list (I just need content ID and Name).

    In C# I'd do this with Umbraco.TypedContentAtXPath("//ContentType")

    But there doesn't seem to be an injectable service available that provides this (or similar functionality) to AngularJS.

    Does anyone know the correct way to get the data I'm looking for?

  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Feb 21, 2022 @ 17:30
    Lee Kelleher
    0

    Hi Neil,

    In AngularJS, the contentResource API has some methods to get content, but as far as I'm aware there aren't any for XPath queries.

    You'd need to make your own API controller (in C#) to query they content cache, and do a fetch (AJAX) call from AngularJS to get the data and populate the dropdown list.


    Alternatively, if you want to use an existing package for this, I made one called Contentment, that has an editor called Data List, which will let you configure a data-source with a list-editor, e.g. Umbraco Content (by XPath) with a Dropdown List. It might save you some dev time?

    Cheers,
    - Lee

  • Neil 37 posts 201 karma points
    Feb 22, 2022 @ 09:31
    Neil
    0

    That's what I feared. I was hoping to avoid an API controller - seemed daft to make two separate HTTP requests just to pre-populate a list at initilisation.

    Should be a simple enough controller to write, I just wanted to check there wasn't something I was missing before commiting to that route.

    Cheers Lee.

  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Feb 22, 2022 @ 17:38
    Lee Kelleher
    100

    Hi Neil,

    It is possible to do it in a single hit, but it get advanced quite quickly - it depends how comfortable you are with C# and defining the property-editor in C# (rather than using the package.manifest file).

    The gist of it is that when you have your own custom DataEditor, you can override the ConfigurationEditor - there is an override method called ToValueEditor - here you can add data to the configuration that gets sent to the AngularJS controller for the property-editor.

    I have code in my Contentment GitHub repo that you could use as a reference - although when most folk take a look at this, they tend to run a mile away! https://github.com/leekelleher/umbraco-contentment/blob/3.1.0/src/Umbraco.Community.Contentment/DataEditors/DataList/DataListConfigurationEditor.cs#L91

    Not sure if this helps or not?

    Cheers,
    - Lee

  • Neil 37 posts 201 karma points
    Feb 23, 2022 @ 10:00
    Neil
    1

    That's perfect, cheers.

    I'm fine with doing it in C# - I assumed that's the route I'd need if it were possible. I'll have a play.

Please Sign in or register to post replies

Write your reply to:

Draft