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 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 {
publicclassGetDataController : SurfaceController {
privatereadonlyIRoutableRequestContext _context;
privatereadonlyIHiveManager _hive;
privatereadonlyIRenderModelFactory _renderModelFactory;
public GetDataController(IRoutableRequestContext context, IHiveManager hive, IRenderModelFactory renderModelFactory) : base(context){
_context = context;
_hive = hive;
_renderModelFactory = renderModelFactory;
}
publicUmbracoHelper Umbraco {
get {
returnnewUmbracoHelper(ControllerContext, _context, _renderModelFactory);
}
}
publicActionResult 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 = newList<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 = newUmbracoContentItem { 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 = newUmbracoAttribute {
Name = attrib.AttributeDefinition.Name.ToString(),
Alias = attrib.AttributeDefinition.Alias
};
var values = newList<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);
}
}
returnnewXmlResult(contentList);
}
}
}
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
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>
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)
is working on a reply...