Copied to clipboard

Flag this post as spam?

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

  • James Hill 2 posts 83 karma points
    3 days ago
    James Hill


    I'm trying to set/access a global site value.

    On my HomePage document type I've created a 'site settings' tab, and within this tab I've added a 'postAuthor' property.

    On the HomePage I can retrive and show the 'postAuthor' value using @Model.Value("postAuthor").

    But, when I use @Model.Value("postAuthor") on the post page, no value is returned?

    Below is the content structure, and I would like to use the global value for the author name from the HomePage 'site settings' tab on other pages below the root node?

    enter image description here

    I've tried different ways, but still cant get thos to work !

  • Johan Runsten 12 posts 123 karma points c-trib
    3 days ago
    Johan Runsten


    You need to get the model for the HomePage node, on your post page, since the properties are defined on it.

    Try Model.Root().Value("postAuthor") or Model.Root<HomePage>().PostAuthor if you're using the model builder.

  • James Hill 2 posts 83 karma points
    2 days ago
    James Hill

    Thanks Johan,

    This worked perfectly for what I needed.

  • Keith 53 posts 194 karma points
    2 days ago

    I do not use this feature myself, so cant comment on how effective it is, but doesn't Umbraco have a fallback option, when getting a model value? I noticed when I was playing around with the template editor UI:

    enter image description here

    In your case, it would give you:

    @Model.Value("postAuthor", fallback: Fallback.ToAncestors)

    Seems neat.

Please Sign in or register to post replies

Write your reply to: