Copied to clipboard

Flag this post as spam?

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


  • blackhawk 313 posts 1368 karma points
    Mar 24, 2017 @ 14:48
    blackhawk
    0

    How to wrap recursive umbraco property fields with HTML

    I have the following Umbraco field in a template.

    @Umbraco.Field("kLPArticle", recursive: true)

    which is powered by Umbraco.MultiNodeTreePicker

    When I add content node(s) to my page that has this Tree Picker, The results display...

    1081, 1082
    

    From my template, how can I wrap each of these category Ids with HTML so that the the final output looks like this...

    <a href="/1081">category node page name </a>
    <a href="/1082">category node page name</a>
    ...
    

    What must I do in my template?

    And beyond that, is there a way to show /content-node-name, rather than /1081?

    Thanks!

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Mar 24, 2017 @ 15:01
    Alex Skrypnyk
    100

    Hi Kensley

    I think you need this code:

    var categories = Umbraco.AssignedContentItem.GetPropertyValue<string>("kLPArticle", true).Split(',').Select(x => Umbraco.TypedContent(int.Parse(x)));
    
    foreach (var category in categories)
    {
        <a href="/@category.Id">@category.Name</a>
    }
    

    Thanks,

    Alex

  • blackhawk 313 posts 1368 karma points
    Mar 24, 2017 @ 15:19
    blackhawk
    0

    awesome, how can I see all of my available property options, other than .Id and .Name? what else can I use?

    Thanks!

  • blackhawk 313 posts 1368 karma points
    Mar 24, 2017 @ 15:28
    blackhawk
    1

    based on your solution, I ended up using something like this...

    @{var categories = Umbraco.AssignedContentItem.GetPropertyValue<string>("kLPArticle", true).Split(',').Select(x => Umbraco.TypedContent(int.Parse(x)));}
    <ul>
        @foreach (var category in categories){<li><a href="/@category.Id">@category.Name</a></li>}
    </ul>   
    

    Thank you so much!

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Mar 24, 2017 @ 15:29
    Alex Skrypnyk
    0

    Glad to help, have a nice weekend!

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Mar 24, 2017 @ 15:21
    Alex Skrypnyk
    1

    Kensley, I'm using Visual Studio, it's easy to see all properties in it.

    Also you can use documentation - https://our.umbraco.org/documentation/reference/querying/ipublishedcontent/

    All properties are described there.

    Thanks,

    Alex

  • blackhawk 313 posts 1368 karma points
    Mar 24, 2017 @ 15:29
    blackhawk
    0

    ahhh - my next level of learning! Thanks for pointing me here.

Please Sign in or register to post replies

Write your reply to:

Draft