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?
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?
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)
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
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
Another way is to traverse the content tree or perhaps query a page by it´s id like
Documentation can be found here: http://our.umbraco.org/documentation/Reference/Mvc/querying
Hope this helps,
/Dennis
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 :)
is working on a reply...