Copied to clipboard

Flag this post as spam?

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


  • Carlos 338 posts 472 karma points
    Jun 21, 2012 @ 18:47
    Carlos
    0

    Get all Creator Names but list them only once Razor

    I am trying to make my own blog. I don't want to use uBlogsy or Blog4Umbraco. I know how to get all the CreatorNames of a specific Nodes, I just need to know how to list them only once vs listing them all for all items.  The code below is currently what I am using but I need to know how to list each Creator Name only once.  Thanks

    I have it started by 

      <ul>
      @foreach(var item in @Model.NodeById(1089).Descendants("ScienceResearchUpdatesPost").OrderBy("CreatorName")){
          <li>@item.CreatorName</li>                                                                                                      
       }
      </ul

  • Jan Skovgaard 11258 posts 23500 karma points MVP 7x admin c-trib
    Jun 21, 2012 @ 21:58
    Jan Skovgaard
    0

    Hi Carlos

    If I understand your question correctly you should be able to use Distinct like Tom does in this post perhaps? http://our.umbraco.org/forum/developers/razor/27295-Find-and-count-unique-values-in-a-dynamicNodeList-

    /Jan

  • Carlos 338 posts 472 karma points
    Jun 21, 2012 @ 22:08
    Carlos
    0

    Jan, I actually found what I was looking for. I found another post 
    http://our.umbraco.org/forum/developers/razor/19020-Is-there-something-like-'GroupBy'?p=0#comment120345 

     

    And took it apart.  This is what I did using a part of their example. I think I was missing a step somewhere. Thanks for getting back to me.  If you have a simpler way or if you see antying that is not necessary in the code, please let me know.  

    string creatorList "";

    <ul>
          @foreach(dynamic node in @Model.NodeById(1089).Descendants("ScienceResearchUpdatesPost").OrderBy("CreatorName"))
          {
            if (creatorList != node.CreatorName)
            {
              <li>@node.CreatorName</li>    
            }
            creatorList node.CreatorName;
          }
          </ul>  

     

     

  • Carlos 338 posts 472 karma points
    Jun 21, 2012 @ 22:31
    Carlos
    0

    Jan,

    One more question. Now that I have the CreatorName list.  I was wondering how I would build a Querystring to show the nodes only shown by a selected name.

    I am using the base pagination Macro and currently have all items of the certain NodeTypeAlias listing.  I now have all of the CreatorNames 

    How would I filter these once a name is selected?

    I tried to make a simple query string but I don't know what to do with it after I have made it.  Any help is appreciated.

    This is my build query string

    var baseNode @Model.AncestorOrSelf("DWTBlogLanding");
      <h3>@Dictionary.DWTAuthors</h3>
          string creatorList "";
      <ul>
          @foreach(dynamic node in @Model.NodeById(1089).Descendants("ScienceResearchUpdatesPost").OrderBy("CreatorName"))
          {
            if (creatorList != node.CreatorName)
            {
              <li><href="@[email protected]">@node.CreatorName</a></li>    
            }
            creatorList node.CreatorName;
          }

         </ul>

     

    Here is my base page that lists the posts of that NodeTypeAlias.

     

      var pagesToList @Model.NodeById(1089).Descendants("ScienceResearchUpdatesPost").OrderBy("CreateDate desc");

      // configuration
      var itemsPerPage String.IsNullOrEmpty(Parameter.ItemsPerPageint.Parse(Parameter.ItemsPerPage);
      var previousLabel String.IsNullOrEmpty(Parameter.PreviousLabel"Previous" Parameter.PreviousLabel;
      var nextLabel String.IsNullOrEmpty(Parameter.NextLabel"Next" Parameter.NextLabel;

      // paging calculations
      var numberOfItems pagesToList.Count();
      int currentPage 1;
      if (!int.TryParse(HttpContext.Current.Request.QueryString["Page"]out currentPage){
        currentPage 1;
      }
      currentPage--;
      var numberOfPages numberOfItems itemsPerPage == Math.Ceiling((decimal)(numberOfItems itemsPerPage)Math.Ceiling((decimal)(numberOfItems itemsPerPage))+1

      <p>
        Total Items@numberOfItems <br />
        Items per Page@itemsPerPage<br />
        Pages@numberOfPages;<br />
        Current Page@(currentPage)
      </p>

     var baseNode @Model.AncestorOrSelf("DWTBlogLanding");
      
      
      <ul class="dwtPostList">
        @foreach(var item in pagesToList.Skip(currentPage*itemsPerPage).Take(itemsPerPage))
        {

         <li>
            <h3>
         <href="http://umbcarlos.dmns.org/@(baseNode.Url)Post/?nid=@(item.Id)&cid=1">@item.Name</a>
               @*<href="@item.Url">
               @item.Name
               </a>*@
           </h3>
         @*TODO Add link to creator name for query string URLing*@
         <div class="dwtPosted">Posted @item.CreateDate by @item.CreatorName</div>
         
         @*Cant get bodyText to show on paging*@

         @*
           @item.bodyText
    *@
         
         <div class="dwtBtnHolder">
         <href="@item.Url" class="buyNowBtn">Read More</a>
         </div>
         </li>
        }
      </ul>

      <div class="pagingPages">
        @{
      // Google style paging links
        if (currentPage 0{
          <href="?page=@(currentPage)">&laquo@previousLabel</a>
        else {
          <span class="pagingDisabled">&laquo@previousLabel</span>
        }
        
        var Pages Enumerable.Range(1(int)numberOfPages);
        foreach(var number in Pages{
          if (number-!= currentPage{
          <href="?page=@number">@number</a>
          else {
          <span class="dwtPagingCurrent">@number</span>
          }

        }

        if (currentPage Pages.Count()-1{
          <href="?page=@(currentPage+2)">@nextLabel &raquo;</a>
        else {
          <span class="pagingDisabled">@nextLabel &raquo;</span>
        }
      }

      </div> 

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies