Copied to clipboard

Flag this post as spam?

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


  • Matt 353 posts 825 karma points
    Feb 23, 2023 @ 15:41
    Matt
    0

    Getting values from home doc type in master template

    Hi,

    I've got a show hide dropdown that I want to appear on every page (quick links)

    I created a nested doc type with a compostiion on the home page and linked it to a partial view.

    It works fine on the home page and the show /hide will work but if I visit any other pages they just error.

    Anyone know whats wrong? I assume its because I'm adding my partial view to the Master template but thats so the show/hide appears on every page.

    Here is my partialview in my master template

    @inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage
    @using Umbraco.Cms.Core.Models;
    
    @{
    
    
        var toolsList = Model.Value<IEnumerable<IPublishedElement>>("toolsLinks");
    }
    
        <div style="display:none" class="app-div">
          <div class="w-container">
            <div data-current="Tab 1" data-easing="ease" data-duration-in="300" data-duration-out="100" class="w-tabs">
              <div class="w-tab-menu">
                <a data-w-tab="Tab 1" class="tab-link-tab-1 w-inline-block w-tab-link w--current">
                  <div>Tools &amp; Links</div>
                </a>
              </div>
              <div class="w-tab-content">
                <div data-w-tab="Tab 1" class="tab-pane-tab-1 w-tab-pane w--tab-active">
                  <div class="app-col w-row">
    
                                           @foreach (var toolspanel in toolsList.Where(x => x.IsVisible()))
        {
    
                                    <div class="w-col w-col-2">
                      <a href="#" class="tools-link-box w-inline-block">
                        <div class="app-wrapper">
                          <div class="app-header-div blue"><img width="16" height="16" src="images/twitter-logo-silhouette_1twitter-logo-silhouette.png" loading="lazy" alt=""></div>
                          <div class="app-text-wrapper">
                            <h4 class="app-name">@toolspanel.Value("toolItem")</h4>
                          </div>
                        </div>
                      </a>
                    </div>
    
                    }
    
    
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
    

    Thanks

  • Huw Reddick 1745 posts 6108 karma points MVP c-trib
    Feb 24, 2023 @ 08:26
    Huw Reddick
    0

    Hi Matt,

    Yes, your problem is that every page will need to contain the toolsLinks property.

    In your patial view yoou need to get a reference to the 'home' page to look up the toolsLinks. Something like

    var site = Umbraco.ContentAtRoot().FirstOrDefault(c=>c.ContentType.Alias == "home");
    var toolsList = site?.Value<IEnumerable<IPublishedElement>>("toolsLinks");
    
Please Sign in or register to post replies

Write your reply to:

Draft