Copied to clipboard

Flag this post as spam?

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


  • vinit 10 posts 83 karma points
    Sep 06, 2023 @ 05:00
    vinit
    1

    Umbraco Reuse component with data

    I want to reuse components with data on other pages. Can you please help me out How can we possible?

  • Marc Goodson 2155 posts 14408 karma points MVP 9x c-trib
    Sep 06, 2023 @ 09:29
    Marc Goodson
    0

    Hi Vinit

    It depends on what you are trying to achieve, but one common pattern would be to create a DocumentType called 'SharedContentFolder' or similar and allow it to be created underneath the homepage of your site.

    Then within this 'SharedContentFolder' you can create other Folder Types that act as 'Repositories' for shared content.

    eg. if you were building a Council Services website you might have many page on the site promoting the local Council Swimming Pool Services, and you might have some planned maintenance scheduled for the future that will require the pool to close for a few days.

    Instead of having to put the same information on every page 'you could'

    Allow under your SharedContentFolder the creation of a new DocType called AlertsFolder. and then allow to be created under the AlertsFolder a new DocumentType called AlertInfo (This DocumentType would not have a Template, you would never visit it's Url directly) - but would allow you to specify a Title, and Rich Text Content to describe the Alert, and an Alert Type, eg Warning, Danger etc...

    You would then in your Content Tree create your Swimming Pool Temporary Closure Content Item in this Alerts repository under the Shared Content Folder.

    Then, any page type that needs to be able to 'Show an Alert' should have added to it a new property called Page Alert, which is of type Content Picker, or (MultinodeTree Picker gives you more options over what can be selected from where).

    The editor can then go to the various pages of the site related to the Swimming Pool and use the new 'Picker' property to Pick the Swimming Pool temporary Closure Content item.

    In your page templates you then can add a Partial View called DisplayAlert.cshtml which contains to check if the Current Page's Alert Picker has anything 'selected', if so then you'll be able to retrieve the details of the Alert that has been picked, and write out the HTML to nicely display the message pull from the picked content item.

    I know that's very specific, and you likely aren't building a Swimming Pool Alert System! - but hopefully it gives you an illustration of/introduction to the type of pattern: Picking other 'Component' Content items and rendering shared content across pages...

    regards

    Marc

Please Sign in or register to post replies

Write your reply to:

Draft