Copied to clipboard

Flag this post as spam?

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


  • Julius Goddard 38 posts 149 karma points
    Feb 12, 2024 @ 08:14
    Julius Goddard
    0

    Best Way To Create Global Components in Umbraco

    Does anyone have any suggestions or links to documentation which outline the best way to create global components in Umbraco?

    Currently, I have a master template called Layout.cshtml which bring in the Header and Footer using @Html.PartialAsync.

    This displays the header and footer correctly on all pages.

    However, as every new page is created, you have to fill in all the elements of the Header and Footer in the CMS for each page that is created: e.g. the links, title, images etc.

    Is there a way to create a global header and footer which is the same on every page that is created? I attempted to create a page called "Website Settings" with the global elements but was unsuccessful:

    enter image description here

    Is there any way to make the data in the "Website Settings" folder globally available on every page?

  • Sebastian Dammark 581 posts 1385 karma points
    Feb 12, 2024 @ 08:44
    Sebastian Dammark
    0

    Hi Julius,

    I would create a doctype called Website which is allowed as root. On this doctype I would then create the Header and Footer properties

    In your case the Home node would then be Website doctype, and then the rest would be what ever they need to be.

  • Julius Goddard 38 posts 149 karma points
    Feb 12, 2024 @ 09:23
    Julius Goddard
    0

    I have made a doctype called website settings and made it available at root.

    I tried accessing the properties using @inherits UmbracoViewPage

    ModelBindingException: Cannot bind source content type Umbraco.Cms.Web.Common.PublishedModels.Home to model type Umbraco.Cms.Web.Common.PublishedModels.WebsiteSettings.

    Do you know how you would access the properties of the above content type?

  • Huw Reddick 1770 posts 6157 karma points MVP c-trib
    Feb 12, 2024 @ 11:43
    Huw Reddick
    0

    try

    Model.AncestorOrSelf<YourNodeType>()
    

    or Model.Root() if you only have a single root node

  • Julius Goddard 38 posts 149 karma points
    Feb 12, 2024 @ 12:58
    Julius Goddard
    0

    Thanks for your response,

    I ended up going with:

    var Home = Umbraco.AssignedContentItem.AncestorOrSelf

    and just setting all the Header and Footer properties on the Home Page - I hope this is OK practice though.

Please Sign in or register to post replies

Write your reply to:

Draft