Copied to clipboard

Flag this post as spam?

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


  • Anthony 4 posts 74 karma points
    May 10, 2022 @ 08:08
    Anthony
    0

    Umbraco Node Relationships - Base Data (Modules & Blocks) and Base Pages

    Hi all,

    I'm hoping somebody within the community can help offer some guidance...

    I am a Product Owner and I inherited Umbraco when starting a new role last year. Unfortunately, we do not currently have dedicated technical support and we have a bit of a skills gap with respect to Umbraco. This is something I'm working hard to resolve over the next few months and beyond, but in the meantime I'm hoping the amazing community may be able to help.

    We are currently on version 7.6.11 of Umbraco - we are planning to upgrade to 8/9 over the next 6-12 months, but that's obviously going to take some time.

    To provide context, a high level summary of our setup is as follows:

    • Multi-site - many international websites hosted on the platform (including multi-lingual variants depending on country)
    • Using Courier
    • Component based template design (providing content editors with flexibility)

    I am trying to understand whether there is a way in Umbraco to programmatically understand document relationships when completing a save and publish event?

    For example, we have the concept of Pages, Modules and Blocks:

    Page and Module Relationships

    • A Page can have a 1-to-many relationship with Modules. We can attach these modules to a page, and decide on the sequencing / order of presenting of the modular components. This is achieved using the MTP property editor to attach such modules to the body of our core page template. We have designed many different types of module components, these are the basic building blocks of the body section of our pages.
    • A single module could be attached to multiple different pages
    • E.g. an example of a module which is attached to many pages is a Marketing email sign up module. For instance, this might be attached to multiple different product based landing pages

    Module and Block Relationships

    • A Module can have a 0-to-many relationship with Blocks. We typically use blocks where a greater degree of flexibility is needed - such as columns of content. Alternatively, if we have a relatively simple requirement and the module doesn't need to scale with a sub component structure, we typically use a Module without the need to create Blocks.
    • A single block could be attached to multiple different modules of the same type
    • E.g. an example of a Module which is made up of multiple blocks is an FAQ accordion module. This type of module could have 8 blocks attached, each representing a Q&A format, with each block representing a single Q&A

    Sorry for the long pre-amble, but think the above is important context to the questions I'm now going to ask.

    1. Block Editing: When making a change to a block and hitting save and publish, is there any way to programmatically understand how many modules the block is attached to, and what the URL path is for the modules the block is attached to? This would be then followed by.....
    2. Module Editing: When making a change to a module and hitting save and publish, is there any way to programmatically understand how many pages the module is attached to, and what the URL path is for the pages the module is attached to?

    In short, when making an edit to either a module or a block, we ultimately want to understand which page URL's have been updated as a result of the edits (as the save and publish is against modules or blocks in this case, rather than the Page URL).

    Hopefully someone may be able to help steer me in the right direction. Thanks in advance :)

  • Anthony 4 posts 74 karma points
    Jun 06, 2022 @ 21:32
    Anthony
    0

    Any help out there friendly people? :)

  • Marc Goodson 2128 posts 14220 karma points MVP 8x c-trib
    Jun 06, 2022 @ 23:08
    Marc Goodson
    0

    Hi Anthony

    Two concepts you want to have a look at...

    Relations - If you look in the Developer section of Umbraco you will find Relations - they are a way to store a relationship between two items in Umbraco, eg content to content or content to member. You can create different 'relation types' (all sites come with a 'relate on copy' relation type -that tick box you see when you copy a node) and then relate two distinct entities together underneath that relation type - and then you can query the items in both directions, eg find all the 'Cousins' of the current node (the family analogy soon breaks down, I mean are they Aunts/Uncles, etc)

    The RelationService is what you use to create relations and to query them:

    https://our.umbraco.com/documentation/reference/management/services/relationservice/

    Content Saving Events - Whenever a content item is saved in the backoffice then two c# events are thrown that you can handle and 'do stuff'...

    https://our.umbraco.com/Documentation/Reference/Events/ContentService-Events-v7

    The idea then would be to create a Relation Type called 'BlocksToPage' or 'ModulesToPage and 'whenever' you save one of your content items, handle the 'saved event', and read the multinode tree picker, to see which blocks or modules have been picked - and then find all the relations for that current page, and create / remove to match the Mutlinode tree picker etc

    Then when one of the modules or blocks are saved, you can handle their saved events, to query the relations API - to find out which pages they have been picked on...

    ... you can even create a custom property editor on the blocks and modules that will list their 'related pages'...

    That's the gist of how you might approach it, but probably depends on what you are trying to do when something is saved, as to whether it's the most performant approach or not!

    regards

    Marc

Please Sign in or register to post replies

Write your reply to:

Draft