protected virtual string GetPropertyValueInternal( DynamicNode model, string propertyAlias, bool recursive ) { string strValue = ""; if ( model != null && !string.IsNullOrEmpty( propertyAlias ) ) { IProperty property = null; if ( !recursive ) { property = model.GetProperty( propertyAlias ); } else { DynamicNode tempModel = model; IProperty tempProperty = tempModel.GetProperty( propertyAlias ); if ( tempProperty != null && !string.IsNullOrEmpty( tempProperty.Value ) ) { property = tempProperty; } while ( property == null && tempModel != null && tempModel.Id > 0 ) { tempModel = tempModel.Parent; if ( tempModel != null ) { tempProperty = tempModel.GetProperty( propertyAlias ); if ( tempProperty != null && !string.IsNullOrEmpty( tempProperty.Value ) ) { property = tempProperty; } } } } if ( property != null ) { strValue = property.Value; } } return strValue; }
/// <summary> /// The site map. /// </summary> /// <param name="renderModel"> /// The render model. /// </param> /// <returns> /// The <see cref="ActionResult"/>. /// </returns> public ActionResult SiteMapTemplate(RenderModel renderModel) { List<SiteMapViewModel> sitemapElements = new List<SiteMapViewModel>(); DynamicNode homepage = new DynamicNode(1089); if (homepage.GetProperty("showInSiteMap") != null && homepage.GetProperty("showInSiteMap").Value == "1") { sitemapElements.Add(new SiteMapViewModel { Url = homepage.Url, LastModified = homepage.UpdateDate }); } DynamicNodeList sitemapPages = homepage.Descendants( n => n.GetProperty("showInSiteMap") != null && n.GetProperty("showInSiteMap").HasValue() && n.GetProperty("showInSiteMap").Value == "1"); foreach (DynamicNode page in sitemapPages) { sitemapElements.Add(new SiteMapViewModel { Url = page.Url, LastModified = page.UpdateDate }); } return this.View("SiteMapTemplate", sitemapElements); }
public static IEnumerable<string> ImageUrls(this RazorLibraryCore ctx, DynamicNode node, string alias, string cropProperty, string cropName) { var mediaProp = node.GetProperty(alias); if (mediaProp != null && !string.IsNullOrWhiteSpace(mediaProp.Value)) { if (mediaProp.Value.Contains('<')) { foreach (var m in new DynamicXml(mediaProp.Value).OfType<DynamicXml>()) { var url = ImageUrlFromXml(ctx, m, cropProperty, cropName); if (!url.IsNullOrWhiteSpace()) yield return url; } } else { //we look like a list ofr ids foreach (var val in mediaProp.Value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)) { int mediaId = 0; if (int.TryParse(val, out mediaId)) { var url = ImageUrlFromMediaItem(ctx, mediaId, cropProperty, cropName); if (!url.IsNullOrWhiteSpace()) yield return url; } } //we look like xml } } }