Copied to clipboard

Flag this post as spam?

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


  • Tom 143 posts 253 karma points
    Mar 19, 2015 @ 13:16
    Tom
    0

    Access Custom template properties in a Macro

    I have the following code that works but I would like to combine the if statement in the foreach where clause
    Note:  
    newsCategory  is a custom property on my newsitem template

      @foreach (var page in CurrentPage.Children.Where("Visible").OrderBy("CreateDate desc"))
        { 
    if (page.newsCategory == "Articles")
    {
    ....
    }

     

    How do I combine the if condition in my where clause?  

    Thanks
    Tom
  • Tim 1193 posts 2655 karma points c-trib
    Mar 19, 2015 @ 15:30
    Tim
    1

    If you wanted to do it with strongly typed models rather than the dynamic ones, the code would be:

    @foreach (var page in Model.Content.Children.Where(a => a.IsVisible() && a.GetPropertyValue("newsCategory","") == "Articles").OrderBy(b => b.CreateDate))
    {
    .......

    I'm not 100% on the dynamic syntax though. I generally prefer to use the strongly typed stuff, as you get intellisense.

    Hope that helps!

  • Tom 143 posts 253 karma points
    Mar 19, 2015 @ 19:26
    Tom
    0

    I like that.  Thanks

     

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies