Copied to clipboard

Flag this post as spam?

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


  • Robert 5 posts 85 karma points
    Oct 16, 2017 @ 07:49
    Robert
    0

    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...

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Oct 16, 2017 @ 21:21
    Alex Skrypnyk
    0

    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

  • Robert 5 posts 85 karma points
    Oct 17, 2017 @ 07:33
    Robert
    0

    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.

  • Yasir Butt 161 posts 371 karma points
    Oct 17, 2017 @ 09:03
    Yasir Butt
    0

    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

  • Robert 5 posts 85 karma points
    Oct 17, 2017 @ 09:43
    Robert
    0

    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.

  • Yasir Butt 161 posts 371 karma points
    Oct 17, 2017 @ 09:47
    Yasir Butt
    0

    okey!

    you can create page type (Blocks) without template and using it just for storing data.

    Yasir

  • Robert 5 posts 85 karma points
    Oct 17, 2017 @ 10:04
    Robert
    0

    Thanks.

    I've had a look around the backend but can't see anything about "blocks".

    How do I create them?

  • Yasir Butt 161 posts 371 karma points
    Oct 17, 2017 @ 10:21
    Yasir Butt
    0

    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 enter image description here

  • Steve Morgan 1346 posts 4453 karma points c-trib
    Oct 18, 2017 @ 07:45
    Steve Morgan
    0

    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

  • Steve Morgan 1346 posts 4453 karma points c-trib
    Oct 18, 2017 @ 08:17
    Steve Morgan
    100

    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; }
        }
    
    }
    

    You can hit this to test from the browser:

    More details here: https://our.umbraco.org/documentation/Reference/Routing/WebApi/

  • Robert 5 posts 85 karma points
    Oct 18, 2017 @ 12:36
    Robert
    0

    Thanks Steve, that's really helpful

Please Sign in or register to post replies

Write your reply to:

Draft