Copied to clipboard

Flag this post as spam?

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


  • Jimmy Dan Mortensen 77 posts 197 karma points
    Jan 05, 2012 @ 11:19
    Jimmy Dan Mortensen
    0

    Children of note that has a specific property = true

    Hi Guys

    I'm trying to list a selection of nodes, that has a certain property = true.

    As an example I want to list all the sales-departments that sells a specific product.

    On @Model i have a Text-string in which i type the exact name of the child.property I want to be true for my list

    So far I've gotten this:

    @inherits umbraco.MacroEngines.DynamicNodeContext
    @{
      var Department = @Model.findDep;
      var parent = @Model.NodeById(1095);
      if (parent != null)
      {
        <ul id="find-dep">
        @foreach (var item in parent.Children.Where("Visible"))
        {
          if(item.Department)
          {
            <li id=@item.Company>
              <a href="@item.Url"><em>@item.Name</em></a>
            </li>
           }
        }
        </ul>
      }
    }

    The @Department returns the correct text-string, but the If-sentence returns nothing.

    How can I use the "Department"-variable as the property-field I want to check. If I hardcode the variable-text the if-sentence works.

    I hope somebody can help me :-)


  • Tom Fulton 2030 posts 4998 karma points c-trib
    Jan 05, 2012 @ 14:31
    Tom Fulton
    0

    Hi,

    So @Model.findDep contains the property alias that you want to check is true or false?

    You could try changing your if statement to:

    if (item.GetPropertyValue(Department) == "1")

    That should work.  Note GetPropertyValue returns a string so you need to check that way.

    But it would probably be best if you could do this in your foreach loop, I think this should work:

        @foreach (var item in parent.Children.Where("Visible && " + Department)) 

    This should be the same as writing "Visible && yourPropertyAlias"

    Hope this helps,
    Tom

  • Jimmy Dan Mortensen 77 posts 197 karma points
    Jan 05, 2012 @ 14:57
    Jimmy Dan Mortensen
    0

    Both things work :-) I took the @foreach solution, as I then didn't need an if-sentence :-)

    Thank you very much :-)
    Jimmy

Please Sign in or register to post replies

Write your reply to:

Draft