Copied to clipboard

Flag this post as spam?

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


  • Jacob Polden 67 posts 177 karma points
    Jun 07, 2012 @ 15:56
    Jacob Polden
    0

    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.

    <ul>
      <li><a href="@blogItem.Url?tag=@hasDate">@hasDate</a></li>
    <li><a href="@blogItem.Url?tag=@hasDate">@hasDate</a></li>
    <li><a href="@blogItem.Url?tag=@hasDate">@hasDate</a></li>
    </ul>

    It would spit out a list of dates like:

    Sept 2011

    Oct 2011

    Dec 2011

     

    Any help will be greatly appreciated!

  • gilad 185 posts 425 karma points
    Jun 07, 2012 @ 16:00
    gilad
    0

    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.

  • Jacob Polden 67 posts 177 karma points
    Jun 07, 2012 @ 16:07
    Jacob Polden
    0
    Thanks for the quick response!
    1. It's a very basic blog, with one blog listing page, with blog post children
    2. It would be displayed on the blog listing page and blog post page, so I imagine it would use the AncestorsOrSelf function
    3. 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
    The idea is that it is a small archive.
  • gilad 185 posts 425 karma points
    Jun 07, 2012 @ 16:30
    gilad
    0

    Hi jacob.

    What is @blogItem , and @HasDate  ??

    Any way - try this :

    <ul>
    @foreach (var item in Model.AncestorOrSelf().Descendants("Month-folder-documentType-alias"))
    {
    if (item.Children.Count > 0)
    {
    <li><a href="@[email protected]">@item.name</a></li>     
    }
    }
    </ul>

    Hope that help , cheers

  • Jacob Polden 67 posts 177 karma points
    Jun 07, 2012 @ 17:23
    Jacob Polden
    0

    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<DateTimedates;
        foreach (var blogPost in Model.AncestorOrSelf("Blog").BlogPost.Where("Visible").OrderBy("createDate desc"))
          {
           DateTime bpDate new DateTime(blogPost.YearblogPost.Month)
           if (!dates.contains(bpDate)
            {
                dates.add(bpdate);
                <li class="month">
                  <href="/[email protected](mmmm,YYYY)"><span>@bpdate.ToString(mmmm,YYYY)</span></a>
                </li>
            }
          }
      }
    </ul>

Please Sign in or register to post replies

Write your reply to:

Draft