Skip to content

Instantly share code, notes, and snippets.

@timw255
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timw255/9057817 to your computer and use it in GitHub Desktop.
Save timw255/9057817 to your computer and use it in GitHub Desktop.
I used this code a while back to find DynamicContent that has been related to another DynamicContent by Guid[]
//This feature is available out of the box in Sitefinity 7+
public DynamicContent CurrentFeature;
protected override void InitializeControls(GenericContainer container)
{
CurrentFeature = this.ResolveDetailItemFromUrl();
if (CurrentFeature != null)
{
var relatedCapabilities = RetrieveRelatedCapabilities(CurrentFeature);
if (relatedCapabilities.Count() > 0)
{
CapabilityRepeater.Visible = true;
CapabilityRepeater.DataSource = relatedCapabilities;
}
}
}
protected virtual DynamicContent ResolveDetailItemFromUrl()
{
var itemUrl = this.GetUrlParameterString(true);
if (itemUrl != null)
{
var urlName = itemUrl.Substring(itemUrl.LastIndexOf('/') + 1);
var providerName = String.Empty;
DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(providerName);
Type featureType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.Features.Feature");
var feature = dynamicModuleManager.GetDataItems(featureType).Where(f => f.UrlName == urlName).FirstOrDefault();
if (feature != null)
{
return feature;
}
}
return null;
}
private IQueryable<DynamicContent> RetrieveRelatedCapabilities(DynamicContent feature)
{
var providerName = String.Empty;
DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(providerName);
Type capabilityType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.Capabilities.Capability");
var myCollection = dynamicModuleManager.GetDataItems(capabilityType).Where(c => c.GetValue<Guid[]>("Features").Contains(feature.Id) && c.Status == ContentLifecycleStatus.Live);
return myCollection;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment