title: Umbraco Razor navigation access custom fields
body: <p>I am trying to build a navigation that automatically includes certain pages depending on settings in the CMS.</p>
  
  <p>I have used the sitemap Partial Macro and have tried to add an if statement that checks a page property like so: <code>@if (!item.HideSubPages) {</code></p>
  
  <p>However, I am just getting the following error: </p>
  
  <pre><code>Umbraco.Core.Models.IPublishedContent' does not contain a definition for 'HideSubPages' and no extension method 'HideSubPages' accepting a first argument of type 'Umbraco.Core.Models.IPublishedContent' could be found (are you missing a using directive or an assembly reference?)
  </code></pre>
  
  <p>Here is my full code</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>@inherits Umbraco.Web.Macros.PartialViewMacroPage
  @using Umbraco.Core.Models
  @using Umbraco.Web
  
  
  @*
      This snippet makes a list of links of all visible pages of the site, as nested unordered HTML lists.
  
      How it works:
      - It uses a custom Razor helper called Traverse() to select and display the markup and links.
  *@
  
  @{ var selection = Model.Content.Site(); }
  
  &lt;div class="sitemap"&gt;
      @* Render the sitemap by passing the root node to the traverse helper, below *@
      @Traverse(selection)
  &lt;/div&gt;
  
  
  @* Helper method to traverse through all descendants *@
  @helper Traverse(IPublishedContent node)
  {
      @* Update the level to reflect how deep you want the sitemap to go *@
      const int maxLevelForSitemap = 4;
  
      @* Select visible children *@
      var selection = node.Children.Where(x =&gt; x.IsVisible() &amp;&amp; x.Level &lt;= maxLevelForSitemap).ToArray();
  
      @* If any items are returned, render a list *@
      if (selection.Length &gt; 0)
      {
          &lt;ul&gt;
              @foreach (var item in selection)
              {
              &lt;li class="level-@item.Level"&gt;
                  &lt;a href="@item.Url"&gt;@item.Name&lt;/a&gt;
                  
                  @* Run the traverse helper again for any child pages *@
                  @if (!item.HideSubPages) {
                      @Traverse(item)
                  }
  
              &lt;/li&gt;
              }
          &lt;/ul&gt;
      }
  }</code></pre>
  </div>
  </div>
  </p>