Copied to clipboard

Flag this post as spam?

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


  • Fredrik.M 2 posts 22 karma points
    Jan 27, 2011 @ 07:39
    Fredrik.M
    0

    Razor and GetMedia by folders id.

    I have just one little question, how do you best get use of GetMedia with Razor? I've created a Razor-macro that takes a page property "imageFolder" and pass it to GetMedia to be able to loop out some items.

    With xslt it's pretty easy and straight forward. Compared to Razor I rather use Xslt instead when it comes to using GetMedia from the umbraco.library.

    Is there some way than this, that doesn't make use of so much xpath. :)

    @using System;
    @using System.Xml.XPath;
    @{
      var currentPg = Model;
      var folderId = 0;
     
      if(currentPg.GetProperty("documentLibrary") !=null) {
        folderId = Convert.ToInt32(currentPg.GetProperty("documentLibrary").Value);                                                        
      }
      var xn = umbraco.library.GetMedia(folderId, true);
      var files = xn.Current.Select("/descendant-or-self::* [@nodeTypeAlias = 'File' or @nodeTypeAlias = 'Image'] /umbracoFile");
    <ul id="document-list">
    @while (files.MoveNext()){
     
      @* get our values *@
      var filePath = files.Current.Value;
      var fileName = files.Current.Evaluate("string(../@nodeName)");                         
      var fileBytes = decimal.Parse(files.Current.Evaluate("string(../umbracoBytes div 1024)").ToString().Replace(".",","));
      var fileExtension = files.Current.Evaluate("string(../umbracoExtension)");
      var fileDescription = files.Current.Evaluate("string(../fileDescription)");
                               
                            
      <li class="file">
        <a href="@filePath" class="external">@fileName</a>
        <div class="file-meta">                     
        <span class="@fileExtension">@fileExtension</span>
        <span class="file-bytes">@fileBytes.ToString("#,###") KB</span>
        <div class="clear"></div>                     
        <p>@fileDescription</p>
        </div>
      </li>
    }
    </ul>
    }
     
  • Jonas Eriksson 930 posts 1825 karma points
    Jan 29, 2011 @ 20:13
    Jonas Eriksson
    0

    Hi Fredrik!

    Short : did you look at uQuery - which has a set of nice helper functions for both content ant media?

    Regards

    Jonas

  • Sebastian Dammark 583 posts 1407 karma points
    Nov 13, 2011 @ 12:43
    Sebastian Dammark
    0

    How do I check if 'files' actually contains any images before I start my <ul> ?

    Now if I select an empty folder I would get <ul></ul> which isn't valid markup.

Please Sign in or register to post replies

Write your reply to:

Draft