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?
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?
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.
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.
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?
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
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.
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 theConfigurationEditor
- there is an override method calledToValueEditor
- 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
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.
is working on a reply...