Copied to clipboard

Flag this post as spam?

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


  • Brett Fullam 119 posts 629 karma points
    May 23, 2017 @ 20:53
    Brett Fullam
    0

    Accessing a property on another page? Umbraco v7.6

    I'm trying to access a property on another page ... specifically from a Related Links property type. I can get get my code to see an existing property value on the page, but I'm having trouble accessing the property fields in a related links property type.

    Here's what I'm working with so far:

    else if (childPage.GetPropertyValue("anchorLinkOption")==true)
                                {
    

    In this first statement, the "anchorLinkOption" property value is accessed and triggers this next part of the conditional statment ... this is working as expected ... but this next part ...

                                var typedRelatedLinksConverted = Model.Content.GetPropertyValue<RelatedLinks>("rLinksTarget");
    
                                if (typedRelatedLinksConverted.Any())
                                {
    

    ... is returning a "null value" (currently) and I'm pretty sure it's only looking at the currently loaded page and not the childPage. So, I'm having trouble rewriting this part of the statement to access the same childpage that had the "anchorLinkOption" property value to access the Related Links property type:

    Model.Content.GetPropertyValue
    

    Any insight or references you can point me to would be greatly appreciated.

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    May 23, 2017 @ 21:35
    Alex Skrypnyk
    0

    Hi Brett

    Try this code:

    var typedRelatedLinksConverte1d = Model.Content.GetPropertyValue<RelatedLinks>("rLinksTarget");
    
    foreach (var child in Model.Content.Children)
    {
        var typedRelatedLinksConverted2 = child.GetPropertyValue<RelatedLinks>("rLinksTarget");
    
        if (typedRelatedLinksConverted2.Any())
        {
        }
    }
    
  • Brett Fullam 119 posts 629 karma points
    May 24, 2017 @ 00:01
    Brett Fullam
    101

    Hey Alex ... this was a side thread I had created to resolve the same issue as the dynamic nav. The code block you shared here didn't work for me, but the code you posted in my other thread worked perfectly!

    Thanks again!

    UPDATE: Here's the link to the completed code that applies Alex's solution for anyone else looking to resolve this:

    How to add anchor links to dynamic navigation?

    https://our.umbraco.org/forum/using-umbraco-and-getting-started/85729-how-to-add-anchor-links-to-dynamic-navigation

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    May 24, 2017 @ 08:53
    Alex Skrypnyk
    0

    Hi Brett

    Glad that we solved this issue. Have a great day!

    Alex

Please Sign in or register to post replies

Write your reply to:

Draft