Get properties from contentResource.js
# help-with-umbraco
j
Using umbraco.resources.contentResource how do I get the bespoke property values from a page - I can get the Name and URL of the page but not properties that i have included in the DocumentType? This is using Umbraco 12.
y
Hello @jonroberts , You can use the contentResource.getById method to get the content data for a specific page. You will need to pass the content's ID as a parameter. For example: umbraco.resources.contentResource.getById(contentId) .then(function(data) { // Handle the retrieved content data here }); replace contentId with the actual ID of the page you want to retrieve content for. Once you have retrieved the content data, you can access the custom properties using the property aliases. The custom property values are stored in the properties object within the content data. For example, if you have a custom property with the alias "customPropertyAlias," you can access its value like this: var customPropertyValue = data.properties.customPropertyAlias; Replace "customPropertyAlias" with the alias of the custom property you want to access.
Here's a complete example of how to retrieve a specific page's custom property values: // Replace contentId with the ID of the page you want to retrieve content for var contentId = 123456789; // Example content ID umbraco.resources.contentResource.getById(contentId) .then(function(data) { // Access custom properties var customPropertyValue = data.properties.customPropertyAlias; // You can access other properties like Name and URL as well var name = data.name; var url = data.urls[0].text; });
j
Hi - thanks for this - does this work in Umbraco 12? I only ask as properties (as in data.properties) doesn't exist in ours.
y
Yes
j
This is our "contentItem":
Do you think we might be missing a reference?
This is our code:
We had been using "key" as the page to get - but tested it with $routeParams.id as a seperate test
5 Views