I am trying to create a razor macro that sounds quite simple but I just can't get my head around it. I am trying to get the macro to look through every month to see if it has content. If it does it would output the month eg "sept 2011" but if it didn't have content it would just go onto the next month.
It's a very basic blog, with one blog listing page, with blog post children
It would be displayed on the blog listing page and blog post page, so I imagine it would use the AncestorsOrSelf function
I meant if it existed, I didn't want the blog to output months with no posts created so it would check before lisitng the months it actually has posts created
Thanks for the response, however I am looking to list the dates, not the actual blog posts, I wrote this as my soloution in the end, hope it helps you understand what I meant to achieve! Thanks for helping!
<ul class="archive add-nav">
@{ List<DateTime> dates; foreach (var blogPost in Model.AncestorOrSelf("Blog").BlogPost.Where("Visible").OrderBy("createDate desc")) { DateTime bpDate = new DateTime(blogPost.Year, blogPost.Month) if (!dates.contains(bpDate) { dates.add(bpdate); <li class="month"> <a href="/[email protected](mmmm,YYYY)"><span>@bpdate.ToString(mmmm,YYYY)</span></a> </li> } } } </ul>
Check content exists by month
I am trying to create a razor macro that sounds quite simple but I just can't get my head around it. I am trying to get the macro to look through every month to see if it has content. If it does it would output the month eg "sept 2011" but if it didn't have content it would just go onto the next month.
It would spit out a list of dates like:
Sept 2011
Oct 2011
Dec 2011
Any help will be greatly appreciated!
Hi jacob.
What is your site/blog structe?
Where on site did you try to output this menu?
What did you mean ti see if it has content? to check if has children? (nodes)
Cheers.
Hi jacob.
What is @blogItem , and @HasDate ??
Any way - try this :
Hope that help , cheers
Thanks for the response, however I am looking to list the dates, not the actual blog posts, I wrote this as my soloution in the end, hope it helps you understand what I meant to achieve! Thanks for helping!
<ul class="archive add-nav">
@{
List<DateTime> dates;
foreach (var blogPost in Model.AncestorOrSelf("Blog").BlogPost.Where("Visible").OrderBy("createDate desc"))
{
DateTime bpDate = new DateTime(blogPost.Year, blogPost.Month)
if (!dates.contains(bpDate)
{
dates.add(bpdate);
<li class="month">
<a href="/[email protected](mmmm,YYYY)"><span>@bpdate.ToString(mmmm,YYYY)</span></a>
</li>
}
}
}
</ul>
is working on a reply...