Copied to clipboard

Flag this post as spam?

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


  • Henrik Ladefoged 30 posts 100 karma points
    Mar 23, 2016 @ 10:26
    Henrik Ladefoged
    0

    Problem getting root property values from pages deeper in the content tree

    Version: Umbraco 7.2.4

    In my content tree i have a main site node with a bunch of separate subsite nodes. The main site and subsite nodes have difference doctypes so i can restrict subsite allowed doctypes (sadly required).

    • main site
    • subsite1
    • subsite2 etc..

    On both doctypes i have Site Setting properties which i need to access.

    I thought the following code would work but it doesn't when i am deeper in the content tree. There is no error but a bool will return false even though it is false.

    bool showSearch = Model.Content.AncestorOrSelf().GetPropertyValue<bool>("showSearch");
    

    I can't use AncestorOrSelf("FrontPage") because i also have the subsite "SubsiteFrontPage" doctype so i really need to access the root without specifying doctype.

  • Andreas Kaltenhuber 107 posts 286 karma points
    Mar 23, 2016 @ 10:39
    Andreas Kaltenhuber
    100

    use

    bool showSearch = Model.Content.AncestorOrSelf(1).GetPropertyValue

    this gets the Root Node of the actual Node

    or use

    IEnumerable

    to get all Nodes at Root Level.

    Cheers, Andreas

  • Henrik Ladefoged 30 posts 100 karma points
    Mar 23, 2016 @ 10:42
    Henrik Ladefoged
    0

    Cheers mate. That did the trick. Lots of frustration prevented :)

Please Sign in or register to post replies

Write your reply to:

Draft