0

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"?

2 Answers2

1

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>
Thomas Krantz
  • 226
  • 2
  • 5
1

You can hook into the Filter event from the underlying PageTreeData control.

Try something like this

yourMenulistControl.Filter += 
       (o, args) => new FilterCompareTo("PageTypeName", "YOURPAGETYPENAME")
                        .Filter(args.Pages);
Greg B
  • 14,597
  • 18
  • 87
  • 141
tompipe
  • 949
  • 6
  • 8