Search code examples
asp.netepiserver

How can I conditionally check a property in the .aspx file inside EpiServer:MenuList?


I'm building a menu in EpiServer where I only want to include items that is of a certain pagetype. If the repeated item has a pagetype that equals "X" then print it out, else don't do nothing.

<ItemTemplate>
 <li>
    <span class="menu-level-1">
      <%# Container.CurrentPage.PageTypeName == "NameOfPageType" ? "Something": "" %>                       
      <span class="menu-divider"></span>
    </span>
 ...
 ..
 .

I want to print out every (who meets the criteria) items pagename, i.e:

<EPiServer:Property PropertyName="PageName" runat="server">

What is the correct syntax for exceuting code rather than printing out "Something"?


Solution

  • You could go with either:

    <%# Container.CurrentPage.PageTypeName == "NameOfPageType" ? Container.CurrentPage.PageName : "" %>
    

    or wrap your Property control with a standard ASP.NET PlaceHolder control:

    <span class="menu-level-1">
      <asp:PlaceHolder runat="server" Visible=<%# Container.CurrentPage.PageTypeName == "NameOfPageType" %> >
            <EPiServer:Property PropertyName="PageName" runat="server" />
          </asp:PlaceHolder>
          <span class="menu-divider"></span>
    </span>