Copied to clipboard

Flag this post as spam?

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


  • sam how 29 posts 129 karma points
    Jan 11, 2023 @ 16:47
    sam how
    0

    Partial View

    Hello, How can I show the value of the property in multiple page using partial view? I tried the code below but its only showing on master. Thank you in advance.

    @using Umbraco.Cms.Web.Common.PublishedModels; @inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage @using ContentModels = Umbraco.Cms.Web.Common.PublishedModels; @{ Layout = null; }

    <footer class="footer">
      <div class="container">
        <h2>@Model.Value("footerAddress")</h2>
      </div>
    </footer>
    
  • Johannes Lantz 156 posts 839 karma points c-trib
    Jan 11, 2023 @ 19:31
    Johannes Lantz
    1

    Hi Sam!

    I am amusing you have the footerAddress on your root node.

    I'd like to think of Model as the current page. So your code won't work on a subpage since the subpage doesn't have the footerAddressproperty. So what you need to do is get the root node. Something like this:

    var root = Model.Root();
    
    <footer class="footer">
      <div class="container">
        <h2>@root.Value("footerAddress")</h2>
      </div>
    </footer>
    

    Hope this helps!

    //Johannes

  • Julien Kulker 75 posts 427 karma points c-trib
    Jan 11, 2023 @ 20:09
    Julien Kulker
    101

    Above is totally correct. You can also do a recursive property.

    https://our.umbraco.com/Documentation/Reference/Querying/IPublishedContent/Properties/#fallbacks

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

    But this is only a best practice when the property is on every node but not filled in on every item

  • Laurin 14 posts 134 karma points
    Jan 12, 2023 @ 13:31
    Laurin
    0

    Thanks Julien. You just helped me reduce my code. I never heard of the fallback option. I just reduced the code by 12 lines.

  • sam how 29 posts 129 karma points
    Jan 12, 2023 @ 13:35
    sam how
    0

    Thank you Julien its working fine now.

Please Sign in or register to post replies

Write your reply to:

Draft