You could use the Content Type service in order to find a list allowed content types if you know the document type's alias. I haven't tested the following helper method but it should give you an idea as to how you can do it:
using System.Collections.Generic;
using System.Linq;
using Umbraco.Core;
using Umbraco.Core.Models;
namespace Application
{
public class ContentTypeHelper
{
public IEnumerable<IContentType> GetAllowedContentTypes(string alias)
{
var retval = new List<IContentType>();
if (string.IsNullOrWhiteSpace(alias))
return retval;
// Use the content type service to find
// the content type passed to the method
var contentTypeService = ApplicationContext.Current.Services.ContentTypeService;
var contentType = contentTypeService.GetContentType(alias);
if (contentType == null)
return retval;
// If we have found the content type, loop through
// each of it's allowed content types and select
// the content type
retval.AddRange(
contentType.AllowedContentTypes.Select(
ct => contentTypeService.GetContentType(ct.Id.Value)));
return retval;
}
}
}
So in your instance, you could use the above method as follows:
var allowed = ContentTypeHelper.GetAllowedContentTypes("Homepage");
Get allowed child node types by code
Hi, I'm trying to get the allowd child node of a document.
Let's say I have a document Called "Homepage", and in his structure the user can create 3 doc types under it
"A", "B", "C" .
How can i get those documents? (DocumentTypeAlias)
Thanks,
Hi Yoni,
You could use the Content Type service in order to find a list allowed content types if you know the document type's alias. I haven't tested the following helper method but it should give you an idea as to how you can do it:
So in your instance, you could use the above method as follows:
Hope that helps.
Thanks, Dan.
is working on a reply...