Everything has gone to plan except my values are not showing.
The @item.Name and @item.Url display, however the values I insert from the document template (i.e. @Umbraco.Field("articleTitle")) do not. No error... just no value is displayed.
The article uses @item.ArticleContents which confused me as previously, the instructions requested.
...replace the Page field tags with the relevant properties e.g.
articlesTitle and articlesBodyText for the Articles Main and the
articleTitle and articleContents for Article Item
The alias was therefore 'articleContents' - yet the code uses 'ArticleContents'
If I attempt to use the @item approach (e.g. @item.articleTitle or @item.ArticleTitle) then I receive errors at runtime (Umbraco.Core.Models.IPublishedContent' does not contain a definition for 'articleTitle' and no extension method 'articleTitle'). It is the same if I use 'ArticleTitle'.
Here's the code.
@inherits Umbraco.Web.Macros.PartialViewMacroPage
@using Umbraco.Web
@*
This snippet makes a list of links to the of children of the current page
using an unordered HTML list.
How it works:
- It uses the Children method to get all child pages
- It then uses the OrderByDescending() method, which takes the property to sort. In this case the page's creation date.
- It then generates links so the visitor can go to each page
*@
@{ var selection = Model.Content.Children.Where(x => x.IsVisible()).OrderByDescending(x => x.CreateDate).ToArray(); }
@if (selection.Length > 0)
{
@foreach (var item in selection)
{
<!-- blog article -->
<article class="blog">
<!-- main heading of the blog -->
<h2><a href="@item.Url">@item.Name</a>@Umbraco.Field("articleTitle")</h2>
<!-- image holder -->
<div class="img-holder">
<img src="~/images/img11.jpg" srcset="images/img11-2x.jpg 2x" alt="Image Description" width="871" height="326">
</div>
<!-- menu items -->
<ul class="menu-item">
<li><a href="#"><span class="icon icon-user"></span>@Umbraco.Field("author")</a></li>
<li><span class="icon icon-calendar"></span><time datetime="@Umbraco.Field("dateOfPublish", formatAsDate: true)">@Umbraco.Field("dateOfPublish", formatAsDate: true)</time></li>
<li><a href="#"><span class="icon icon-bubbles"></span>@Umbraco.Field("commentsQuantity") Quantity comments</a></li>
</ul>
<p>
@Umbraco.Field("bodyText")
</p>
<!-- btn holder -->
<div class="btn-holder">
<a href="#" class="btn btn-primary">Read more <span class="icon icon-arrow-right"></span></a>
</div>
</article>
}
}
Clearly I'm misunderstanding or not following the article properly.
I think the problem is that you want to show fields from the child items you are looping over, but your code wants to show them from the page your are current on (the overview)
@Umbraco.Field("articleTitle")
This code will try to render the property with alias "articleTitle" from the page you are currently on...so the overview page.
What you need is :
@Umbraco.Field(item, "articleTitle")
That way it knows it has too look for the field on the current item in the loop.
" error CS1502: The best overloaded method match for 'System.Web.WebPages.WebPageExecutingBase.Write(System.Web.WebPages.HelperResult)' has some invalid arguments"
This confuses me because I had tried that approach and the Media Picker code segment I'm using does follow that format and works fine:
@{
var blogImage = item.GetPropertyValue<IPublishedContent>("articleImage");
if (blogImage != null)
{
<img src="@blogImage.Url" width="871" height="326" alt="@blogImage.GetPropertyValue("alt")" />
}
}
It'd be good to understand why that wasn't working... I'm also not sure why the articles seem to omit this.
Umbraco 7 Partial View Macro File (from snippet) is not showing values
I'm following this tutorial: https://our.umbraco.com/documentation/tutorials/creating-basic-site/Articles-Parent-and-Article-Items
Everything has gone to plan except my values are not showing.
The @item.Name and @item.Url display, however the values I insert from the document template (i.e. @Umbraco.Field("articleTitle")) do not. No error... just no value is displayed.
The article uses @item.ArticleContents which confused me as previously, the instructions requested.
The alias was therefore 'articleContents' - yet the code uses 'ArticleContents'
If I attempt to use the @item approach (e.g. @item.articleTitle or @item.ArticleTitle) then I receive errors at runtime (Umbraco.Core.Models.IPublishedContent' does not contain a definition for 'articleTitle' and no extension method 'articleTitle'). It is the same if I use 'ArticleTitle'.
Here's the code.
Clearly I'm misunderstanding or not following the article properly.
Hi Chris,
I think the problem is that you want to show fields from the child items you are looping over, but your code wants to show them from the page your are current on (the overview)
This code will try to render the property with alias "articleTitle" from the page you are currently on...so the overview page.
What you need is :
That way it knows it has too look for the field on the current item in the loop.
Or you could use :
Could you try that ?
Dave
Fantastic. That's working. Much obliged.
Interestingly,
worked perfectly
but
caused a System.Web.HttpCompileException error:
" error CS1502: The best overloaded method match for 'System.Web.WebPages.WebPageExecutingBase.Write(System.Web.WebPages.HelperResult)' has some invalid arguments"
This confuses me because I had tried that approach and the Media Picker code segment I'm using does follow that format and works fine:
It'd be good to understand why that wasn't working... I'm also not sure why the articles seem to omit this.
Great to be cracking on. Thanks again.
Hi Chris,
Glad to hear you got it working.
Maybe you can create an issue for the documentation that the example code is not working correctly.
The documentation is open source as well so people are constantly contributing to it as well.
You could raise your issue here : https://github.com/umbraco/UmbracoDocs/issues
Dave
is working on a reply...