How can I pass data to my JavaScript? For example, I have a content/page with a blocklist, and inside the blocklist, I want to get the value of a data type "text" and pass it to my JavaScript. What is the most efficient way to do this?
I was able to fetch the blocklist properties inside my blocklist (using the controller i created) and fetch it using javascript but I was not able to get/show the values of the data types in my javascript
public class TestingApiController: UmbracoApiController
{
private readonly IUmbracoContextAccessor _umbracoContextAccessor;
public TestingApiController(IUmbracoContextAccessor umbracoContextAccessor)
{
_umbracoContextAccessor = umbracoContextAccessor;
}
[HttpGet]
public ActionResult<IEnumerable<string>> GetAll()
{
if (!_umbracoContextAccessor.TryGetUmbracoContext(out var context))
{
return Problem("Unable to get Umbraco context.");
}
if (context.Content == null)
{
return Problem("Content cache is null.");
}
var contentType = context.Content.GetContentType(ImageAndTextBlock.ModelTypeAlias);
if (contentType == null)
{
return Problem($"Content type for '{ImageAndTextBlock.ModelTypeAlias}' not found.");
}
var blockListProperties = contentType.PropertyTypes
.Select(pt => new
{
PropertyName = pt.DataType,
DataTypeId = pt.DataType.Id,
DataTypeName = pt.DataType.Configuration.ToJson()
});
if (!blockListProperties.Any())
{
return Ok("No Block List properties found for the SsoPage content type.");
}
return Ok(blockListProperties);
}
}
Umbraco CMS Data to javascript
How can I pass data to my JavaScript? For example, I have a content/page with a blocklist, and inside the blocklist, I want to get the value of a data type "text" and pass it to my JavaScript. What is the most efficient way to do this?
I was able to fetch the blocklist properties inside my blocklist (using the controller i created) and fetch it using javascript but I was not able to get/show the values of the data types in my javascript
public class TestingApiController: UmbracoApiController { private readonly IUmbracoContextAccessor _umbracoContextAccessor;
is working on a reply...