We're evaluating Umbraco to see if it can be used as a repository to store and retrieve individual content items rather than as a CMS/backend for a complete web site with complete pages.
We realise that it is possible, we could create faux pages, hang content items off those pages and then import them into our web application, but Umbraco doesn't appear to have native functionality to store individual content items in a hierarchical, logical manner, outside of pages.
This is completely possible. You just need to create "Document Types" to contain your blocks of content. You can structure this however you need (perhaps creating a "Folder" Document Type to provide the ability to add structure / organisation to your data).
When you create these document types choose the option for no templates - then there are no "pages" to serve then. To access the data you can then create an API (Umbraco's API controllers are built on WebAPI so super easy to do).
An alternative would be to use the template but render some XML / JSON but it would be much cleaner to use the API.
I'd probably still create a "Home" node with a template just for testing and then underneath a parent node for each type of content. Create an API Controller in VS and then query your nodes from that. Use the UmbracoHelper - get the home node then locate the node you wish to render from and return it as a JSON object by just returning the model.
If you need to store list / repeating items without wanting to create node for each piece of content look at the Nested content - this will allow you to create complex structures very easily - these are just doc types within doc types.
Here's a quick example of an API Controller that returns some node content. You'll obviously need to change the code to match your doc type aliases and shouldn't put models in the same file etc etc but it demos the functionality.
using System.Collections.Generic;
using Umbraco.Web;
using Umbraco.Core.Models;
using Umbraco.Web.WebApi;
using System.Linq;
namespace MyNameSpace.ApiControllers
{
public class TestApiController : UmbracoApiController
{
public string GetHelloWorld()
{
return "Hello World";
}
public List<SomeApiResponseModel> GetTestContentItems(SomeApiRequestModel request)
{
var response = new List<SomeApiResponseModel>();
var _umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
var homeNode = _umbracoHelper.TypedContentAtRoot().FirstOrDefault();
if(homeNode != null)
{
var testContentRoot = homeNode.Children("ssHome").FirstOrDefault();
// here you might add filtering from your request
foreach(var contentNode in testContentRoot.Children())
{
response.Add(new SomeApiResponseModel
{
SomeOtherProperty = contentNode.Id,
SomeTestProperty = contentNode.Name
});
}
}
return response;
}
}
public class SomeApiResponseModel
{
public string SomeTestProperty { get; set; }
public int SomeOtherProperty { get; set; }
}
public class SomeApiRequestModel
{
public int PageNumber { get; set; }
public int Year { get; set; }
}
}
Serving/storing individual content items
We're evaluating Umbraco to see if it can be used as a repository to store and retrieve individual content items rather than as a CMS/backend for a complete web site with complete pages.
We realise that it is possible, we could create faux pages, hang content items off those pages and then import them into our web application, but Umbraco doesn't appear to have native functionality to store individual content items in a hierarchical, logical manner, outside of pages.
Is that correct, or are we missing something?
Thanks...
Hi Robert
What did you mean "to store individual content items in a hierarchical, logical manner, outside of pages"?
Can you give some examples?
Thanks,
Alex
Hi Alex,
Basically, what I mean is can you store content items (such as blocks of editable text that would normally be part of a page), outside of a page?
We don't want Umbraco to serve whole pages, we just want to pull individual content items into our web application.
And we want to be able to organise those content items somehow outside of any page structure.
if i got it correctly that you want to make some modules/blocks independently then you want to use it in your pages whereever. is it?
Yes! it is possible.
you may use Grid Layout and create your grid editors
OR
Use Grid layout and create your modules/blocks seperately using page types then use them in the grid page
Yasir
Thanks, but we don't want to use Umbraco for layout at all.
We'll be ignoring pages and layout completely, we just want to store and retrieve individual content items, outside of any pages or page layout.
okey!
you can create page type (Blocks) without template and using it just for storing data.
Yasir
Thanks.
I've had a look around the backend but can't see anything about "blocks".
How do I create them?
there is no blocks but document type.
you can create any kind of data structure using document type and may call it blocks for yourself.
i created same thing called modules see image below
Hi,
This is completely possible. You just need to create "Document Types" to contain your blocks of content. You can structure this however you need (perhaps creating a "Folder" Document Type to provide the ability to add structure / organisation to your data).
When you create these document types choose the option for no templates - then there are no "pages" to serve then. To access the data you can then create an API (Umbraco's API controllers are built on WebAPI so super easy to do).
An alternative would be to use the template but render some XML / JSON but it would be much cleaner to use the API.
I'd probably still create a "Home" node with a template just for testing and then underneath a parent node for each type of content. Create an API Controller in VS and then query your nodes from that. Use the UmbracoHelper - get the home node then locate the node you wish to render from and return it as a JSON object by just returning the model.
If you need to store list / repeating items without wanting to create node for each piece of content look at the Nested content - this will allow you to create complex structures very easily - these are just doc types within doc types.
https://our.umbraco.org/documentation/getting-started/backoffice/Property-Editors/Built-in-Property-Editors/Nested-Content
HTH
Steve
Here's a quick example of an API Controller that returns some node content. You'll obviously need to change the code to match your doc type aliases and shouldn't put models in the same file etc etc but it demos the functionality.
You can hit this to test from the browser:
More details here: https://our.umbraco.org/documentation/Reference/Routing/WebApi/
Thanks Steve, that's really helpful
is working on a reply...