Copied to clipboard

Flag this post as spam?

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


  • Tony Groome 261 posts 804 karma points
    Dec 31, 2014 @ 15:50
    Tony Groome
    0

    Using custom fields

    Hi All

    I am trying to use a custom field in my markup, but it won't display. The custom field I am trying to use is from a different document type, does this matter?

    <div class="section">

     

                    <span style="line-height: 1.4em; font-size: 16px; font-weight: bold;">@Umbraco.Field("hr_header")</span>

                </div>

                <div class="section">

                    <P>@Umbraco.Field("contentitm2col1")<P>

                    <p><a class="buttonGrey block w130" target="_blank" href="/" rel="nofollow">

                        Read More

                        <span class="arrow">></span>

                    </a>

                    </p>

                </div>

    This is the problem field @Umbraco.Field("hr_header") If I use an Umbraco field like created Date it works fine, or a custom field from the same document type. Is there a way around this?

    Thanks.

    Tony

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Dec 31, 2014 @ 16:01
    Dennis Aaen
    0

    Hi Tony,

    The problem is that the @Umbraco.Field refers to the CurrentPage, and if the field isn't on the document type for the current page then is empty

    But if the value is on one of the ancestor pages you could make the field recrusive, this means that it will go up in the content tree until it finds the value.

    The way you could do this is like

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

    Another way is to traverse the content tree or perhaps query a page by it´s id like

    //to return the strongly typed (Umbraco.Core.Models.IPublishedContent) object 
    @Umbraco.TypedContent(1234)

    //to return the dynamic representation:
    @Umbraco.Content(1234)

    Documentation can be found here: http://our.umbraco.org/documentation/Reference/Mvc/querying

    Hope this helps,

    /Dennis

  • Tony Groome 261 posts 804 karma points
    Dec 31, 2014 @ 16:15
    Tony Groome
    0

    Hi Dennis

    Thanks for that. The recursive doesn't work, so I guess it will have to be by id. I didn't realise each field had an id too. Time for a strong coffee!

    Thanks

    Tony

    ps Happy New Year :) 

Please Sign in or register to post replies

Write your reply to:

Draft