Copied to clipboard

Flag this post as spam?

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


  • Lee 1130 posts 3088 karma points
    Oct 24, 2011 @ 17:26
    Lee
    0

    Can This Be Easily Converted To Razor?

    I'm trying to port over some of my XSLT macros to use Razor, but looking at the chaetsheet I don't think this is easily possible is it?

    $currentPage/ancestor-or-self::* [@isDoc]/* [@isDoc and string(ShowInFooter) = '1']

     

  • Rodion Novoselov 694 posts 859 karma points
    Oct 25, 2011 @ 00:04
    Rodion Novoselov
    0

    Hi. Perhaps something like this:

    Model.AncestorsOrSelf(node => node.ShowInFooter);

    (I'm not a great expert in umbraco razor)

  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Oct 25, 2011 @ 14:42
    Dan Diplo
    0

    This should work:

    Model.AncestorsOrSelf().Where("ShowInFooter")
  • Lee 1130 posts 3088 karma points
    Nov 14, 2011 @ 15:41
    Lee
    0

    Hmmm nope I can see the nodes have the property and its either 1 or 0, Dans suggestion above doesn't work and even this doesn't work?

    Model.AncestorsOrSelf().Where("showInFooter == 1")

    Am I missing something?

  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Nov 14, 2011 @ 20:56
    Dan Diplo
    0

    What I posted should work if your property is a true/false property. I've used the same code myself loads of times without a problem.

    Obviously it will only look up the tree, so if your nodes can be anywhere in the tree then it won't find them. To select nodes at any level you'd have to do:

    Model.AncestorOrSelf().DescendantsOrSelf().Where("ShowInFooter")

    If that doesn't work then something is weird in your set-up!

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Nov 15, 2011 @ 09:52
    Chriztian Steinmeier
    0

    The original XPath does this:

    - Find all the ancestor Documents including currentPage and on *each of those*, take any child Document having the showInFooter property checked.

    So I'd wager that you'd need to do something like this in Razor:

    Model.AncestorsOrSelf().Children.Where("showInFooter")

    - But I have a feeling that you can't dot-Where on the Children part...?

    /Chriztian

  • Adi 17 posts 36 karma points
    Nov 16, 2011 @ 17:09
    Adi
    0

    add something like this to your filter criteria

    var filter = criteria.Field("showInFooter", "1");

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Nov 17, 2011 @ 19:12
    Sebastiaan Janssen
    1

    @Chriztian that should (almost) work just fine!

    The problem here is that you're using AncestorsOrSelf.. It has an extra "s" befor "OrSelf" and what you SHOULD be using it AncestorOrSelf:

    @foreach (var item in Model.AncestorOrSelf().Children.Where("showInFooter"))
    {
        @item.Name <br />
    }

     

Please Sign in or register to post replies

Write your reply to:

Draft