Copied to clipboard

Flag this post as spam?

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


  • Aditya.A 77 posts 96 karma points
    Jul 26, 2013 @ 09:28
    Aditya.A
    0

    pick images from folder to display in the slider of home page

    Hi Guys n Gals

    I want to do something fairly straightforward but can find no help for it.i need to develop a home page carousel.

    now i want a macro which will pick the images from the a folder in media,and display them in the home page slider.

    as per the rewquirements i have to create a macro to fetch the images from the folder in media.and display them on the page.

    we are using the "flexslider" javascript to do the slider effect.

    need urgently

  • Fuji Kusaka 2203 posts 4220 karma points
    Jul 26, 2013 @ 10:02
    Fuji Kusaka
    0

    Hi,

    What you could do is make use of Media Picker. Add Media Picker to your documentType "Homepage" then pick the folder you have the images store in media section.

    If you are using razor you can try this

      var mediaPicker = @Model.propertyAlias;

    if (!String.IsNullOrEmpty(mediaPicker)){
    int folderId = Convert.ToInt32(mediaPicker);
    var mediaFolder = new Media(folderId);

    if (mediaFolder.ChildCount > 0) // Check if any Media Images present
    {
    IEnumerable Folder = mediaFolder.GetChildMedia().Where(x => x.ContentType.Alias == "Image"); // Here you can double check if media file is of type Image
    foreach (var img in Folder)
    {

    }
    }

    }

     

    Hope this helps

     

     

  • Aditya.A 77 posts 96 karma points
    Jul 26, 2013 @ 10:27
    Aditya.A
    0

    Hi thank u for quicke response...

    Here is wat i get 

     

    "Error occured

    c:\Websites\Veet2013Q1\Source\Veet.Web\macroScripts\635104094262690434_Home-carousel.cshtml(29): error CS0103: The name 'img' does not exist in the current context"

    WAT I have done :

    media picker name : mediaPicker

    Media folder name : Homecarousel

    cshtml : Home-carosel

    inserted the macro Homecrsl in template.

     

    @inherits umbraco.MacroEngines.DynamicNodeContext

     

    @*

    Model = The current page the macro is executed on

    @Model.bodyText

     

    Parameter = collection of parameter values passed from the macro

    @Paramter.myParam

     

        Library = utillity library with common methods

       @Library.NodeById(1233)

    *@

     

     

     

    @* The fun starts here *@

     

    var mediaPicker = @Model.companyMediaFolder;

      

     if (!String.IsNullOrEmpty(mediaPicker)){

        int folderId = Convert.ToInt32(mediaPicker);

            var mediaFolder = new Media(folderId);

         

               if (mediaFolder.ChildCount > 0) // Check if any Media Images present

                {

     IEnumerable<Media> Folder = mediaFolder.GetChildMedia().Where(x => x.ContentType.Alias == "Image"); // Here you can double check if media file is of type Image 

                    foreach (var img in Folder)

                    {                      

                         <li><img src= "@img.getProperty("umbracoFile").Value" alt="" /></a></li>

                    }

                }

     

    can u suggest how to include the inputs...

     

    sory to bother u again.....but imp

     

     

     

     

     

  • Fuji Kusaka 2203 posts 4220 karma points
    Jul 26, 2013 @ 11:08
    Fuji Kusaka
    0

    Ah add this namespace

    @using umbraco.cms.businesslogic.media;

     

  • Aditya.A 77 posts 96 karma points
    Jul 26, 2013 @ 11:18
    Aditya.A
    0

    @inherits umbraco.MacroEngines.DynamicNodeContext;

    @using umbraco.cms.businesslogic.media;

     

     

    var mediaPicker = @Model.companyMediaFolder;

     

      

     if (!String.IsNullOrEmpty(mediaPicker))

     {

     

        int folderId = Convert.ToInt32(mediaPicker);

     

            var mediaFolder = new Media(folderId);

     

         

     

               if (mediaFolder.ChildCount > 0) 

     

                {

     

     IEnumerable<Media> Folder = mediaFolder.GetChildMedia().Where(x => x.ContentType.Alias == "Image"); 

     

                    foreach (var img in Folder)

     

                    {                      

     

                         <li><img src= "@img.getProperty("umbracoFile").Value" alt="" /></a></li>

     

                    }

     

                }

     

     }

     

     

    Error occured

    c:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\d72e9d2d\ce918128\App_Web_635104126816380434_home-carousel.cshtml.70df5e80.hhewcmkl.0.cs(35): error CS1514: { expected

     

    :(

     

     

  • Fuji Kusaka 2203 posts 4220 karma points
    Jul 26, 2013 @ 11:35
    Fuji Kusaka
    0

    Looks like you are missing @{ after the namespace !

    @inherits umbraco.MacroEngines.DynamicNodeContext;
    @using umbraco.cms.businesslogic.media;
    @{
    var mediaPicker = @Model.companyMediaFolder;  
     if (!String.IsNullOrEmpty(mediaPicker))  {
        int folderId = Convert.ToInt32(mediaPicker);         var mediaFolder = new Media(folderId); 
               if (mediaFolder.ChildCount > 0)  
                {
     IEnumerable<Media> Folder = mediaFolder.GetChildMedia().Where(x => x.ContentType.Alias == "Image"); 
                    foreach (var img in Folder)   {                        <li><img src= "@img.getProperty("umbracoFile").Value" alt="" /></a></li> }
                }  }
  • Aditya.A 77 posts 96 karma points
    Jul 26, 2013 @ 12:20
    Aditya.A
    0

    im am really sorry to ask u stupid qs...but it is also now working..

     

    can u help in giving more details..like the name of folder,media picker, and how they should be refered in the cshtml and all

    ver very urgent friend

  • Fuji Kusaka 2203 posts 4220 karma points
    Jul 26, 2013 @ 12:26
    Fuji Kusaka
    0

    can you please tell me which version of umbraco you are using and what property alias you are using for the media picker ?

  • Aditya.A 77 posts 96 karma points
    Jul 26, 2013 @ 13:08
    Aditya.A
    0

    umbraco v 4.11.8 (Assembly version: 1.0.4869.17899)

    Type : Media Picker

    name :mediaPickerH

    alias : mediaPickerH

    Folder name :Homecarousel

    now can u please provide me with the cshtml code and name,razor name ..thank u in advance

  • Fuji Kusaka 2203 posts 4220 karma points
    Jul 26, 2013 @ 13:43
    Fuji Kusaka
    0
    @inherits umbraco.MacroEngines.DynamicNodeContext
    @using umbraco.cms.businesslogic.media;
    @{   
    var mediaPicker = @Model.mediaPickerH;
        if (!String.IsNullOrEmpty(mediaPicker))    {
            int folderId = Convert.ToInt32(mediaPicker);
            var mediaFolder = new Media(folderId);

            if (mediaFolder.ChildCount > 0)        {
                IEnumerable<Media> Folder = mediaFolder.GetChildMedia().Where(x => x.ContentType.Alias == "Image");
                foreach (var img in Folder)           {             
                          <li><img src= "@img.getProperty("umbracoFile").Value" alt="" /></li> 
                }
        }
      }
    }

    Here you are dont forget to choose the folder from your homepage 

  • Aditya.A 77 posts 96 karma points
    Jul 26, 2013 @ 23:23
    Aditya.A
    0

    dear friend u really rock

    u saved my day thanks a lot i works like miracle

    have a very nice day

Please Sign in or register to post replies

Write your reply to:

Draft