Copied to clipboard

Flag this post as spam?

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


  • Vincent Ashby-Smith 67 posts 196 karma points
    Jul 08, 2009 @ 16:27
    Vincent Ashby-Smith
    0

    Parent page properties

    Hi is it possible to get the properties of a parent page from a child page. So say i have a mainHeader property in the parent page, how can i get these propeties in the child page? I've found how to get the parentID using @parentID but not sure how to access the property mainHeader from this.

  • Warren Buckley 2089 posts 4578 karma points MVP ∞ admin hq c-trib
    Jul 08, 2009 @ 16:36
    Warren Buckley
    101

    As an umbraco:item filed in your masterpage use this:

    <umbraco:Item field="mainHeader" recursive="true" runat="server"></umbraco:Item>
  • Roel Snetselaar 151 posts 305 karma points
    Jul 08, 2009 @ 17:01
    Roel Snetselaar
    0

    Warren is talking about the recursive="true" parameter. This works if the same property exists in the parent page as well as in the childpage.

    For example if you have a mainHeader property in your childpage which is empty, the recursive="true" parameter will make Umbraco look for the same property on the parentpage. If it does contain a value on the parentpage it will render it in the childpage.

    But what about properties that do not exist on a certain childpage? But do exist on the parentpage? I guess you can do it with an xpath node, something like ./ to go up in the XML. However I did not use this in Umbraco myself yet.

  • Warren Buckley 2089 posts 4578 karma points MVP ∞ admin hq c-trib
    Jul 08, 2009 @ 17:08
    Warren Buckley
    1

    Roel thanks for explaining my snippet.
    In regards to the property not even existing on the child page but on the parent that will work perfectly fine as well. (As far as I remember)

    It will basically walk all the way up the tree, going through each parent until it finds the propety and a value to ouput/display.
    I hope that makes sense.

  • Roel Snetselaar 151 posts 305 karma points
    Jul 08, 2009 @ 17:14
    Roel Snetselaar
    0
    Quote: In regards to the property not even existing on the child page but on the parent that will work perfectly fine as well. (As far as I remember)

    Ok, didn't know that. So no playing around with Xpath to move up in the XML. Will give this a try this evening. Thanks.

  • Warren Buckley 2089 posts 4578 karma points MVP ∞ admin hq c-trib
    Jul 08, 2009 @ 17:16
    Warren Buckley
    0

    No problem report back here just in case I am wrong. Not used it for a little while.

  • Roel Snetselaar 151 posts 305 karma points
    Jul 08, 2009 @ 22:31
    Roel Snetselaar
    2

    It works, here is what I did:

    - created a parentpage
    - added property mainHeader
    - added property bodyText
    - created a childpage under the parentpage
    - added property bodyText
    - in template of both the parentpage and the childpage I inserted umbraco:item fields for mainHeader and bodyText except in the childpage template I made the mainHeader field recursive

    As a result the mainHeader field is also rendered into the childpage, which was loaded from the parentpage by Umbraco.

     

  • 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