Copied to clipboard

Flag this post as spam?

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


  • Mike Donner 2 posts 22 karma points
    May 02, 2012 @ 17:22
    Mike Donner
    0

    Get content from a specific folder in the tree

    I am using Umbraco 5 in a content storage senario and I am trying to get the content in a specific folder (passed as a parameter).  I have looked at the stuff on getting content from the media folder but I cannot see how it could work for me.  Anyone got an idea how I can go about doing this?

    Thanks!

    Mike

  • Aaron 14 posts 34 karma points
    May 03, 2012 @ 03:03
    Aaron
    0

    This is how I am doing somehting like what you are after, there could be a better way though.

     

    @{var galleryFolder = Hive.Content.GetById((string)DynamicModel.GalleryMediaFolder);}

    <div class="am-container" id="am-container" style="margin: 110px auto;">
    @foreach (var image in galleryFolder.Children())
    {
        <a rel="image" href="@image.NiceUrl()"><img src="@image.NiceUrl()" title="@image.UrlName"></img></a>
    }
    </div>

  • Mike Donner 2 posts 22 karma points
    May 03, 2012 @ 15:33
    Mike Donner
    0

    Thanks Aaron, but I am not trying to get images or items from a media gallery.  Here is the tree structure:

    I want to get the dependent items in the Highlights document type for a specific PublishedArea.  I am trying to do this in a class so I can use it for all my web sites.  I have a GetData class which returns all the UmbracoContent but I need to be able to pull the decendents of a paricular node, this one being Highlights.

    Thanks.

    EDIT:

    Here is my code from the GetDataController class (it is a separate class from the umbraco site that drops a dll in the umbraco bin folder so it can be referenced)

    namespace Umbraco.GetData { 
        public class GetDataController : SurfaceController { 
            private readonly IRoutableRequestContext _context;
            private readonly IHiveManager            _hive;
            private readonly IRenderModelFactory     _renderModelFactory; 
    
    public
     GetDataController(IRoutableRequestContext context, IHiveManager hive, IRenderModelFactory renderModelFactory) : base(context){ _context            = context; _hive               = hive; _renderModelFactory = renderModelFactory; } public UmbracoHelper Umbraco { get { return new UmbracoHelper(ControllerContext, _context, _renderModelFactory); } } public ActionResult Index(String contentType, String contentName, String publishArea) { List<Content> result; List<String> publishAreas = null; // // fetch the right content type // if (String.IsNullOrEmpty(contentType)) { result = _hive.QueryContent()   .OfRevisionType(FixedStatusTypes.Published)   .ToList(); } else { result = _hive.QueryContent()   .OfRevisionType(FixedStatusTypes.Published)   .Where(x => x.ContentType.Alias == contentType)   .ToList(); } var contentList = new List<UmbracoContentItem>(); foreach (var item in result) { // // if we are looking for something by name, it must match if (!String.IsNullOrEmpty(contentName) && (contentName.ToLower() != item.Name.ToLower())) continue; var contentItem = new UmbracoContentItem {
    Id = item.Id.Value.ToString(), UrlName = item.UrlName, Name    = item.Name, ContentAlias = item.ContentType.Alias, ContentName  = item.ContentType.Name, Host        = ControllerContext.RequestContext.HttpContext.Request.Url != null ?
    ControllerContext.RequestContext.HttpContext.Request.Url.Host : "" }; foreach (var attrib in item.Attributes) {
    if (attrib.DynamicValue != null) { var contentAttrib = new UmbracoAttribute { Name = attrib.AttributeDefinition.Name.ToString(), Alias = attrib.AttributeDefinition.Alias   }; var values = new List<string>(); if (attrib.AttributeDefinition.AttributeType.Name.ToString() == "Uploader") { try { values.Add(Umbraco.GetMediaUrl(item.Id.ToString(), contentAttrib.Alias)); } catch {} } else { try { foreach (string s in attrib.DynamicValue.Values) { values.Add(s); } } catch { values.Add(attrib.DynamicValue.ToString()); } } if (contentAttrib.Name.Contains("Publish Areas")) publishAreas = values; contentAttrib.Values = values.ToArray(); contentItem.Attributes.Add(contentAttrib); } } if (String.IsNullOrEmpty(publishArea)) { contentList.Add(contentItem); } else { if (publishAreas.Contains(publishArea)) contentList.Add(contentItem); } } return new XmlResult(contentList); } } }
Please Sign in or register to post replies

Write your reply to:

Draft