本文整理汇总了C#中Content.Field方法的典型用法代码示例。如果您正苦于以下问题:C# Content.Field方法的具体用法?C# Content.Field怎么用?C# Content.Field使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Content
的用法示例。
在下文中一共展示了Content.Field方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: getMediaUrl
private static string getMediaUrl(Content content, string fieldAlias, int size)
{
UrlHelper _urlHelper = new UrlHelper(((MvcHandler)HttpContext.Current.Handler).RequestContext);
var url = _urlHelper.GetMediaUrl(content, fieldAlias, size);
if (url == null || !url.StartsWith("/"))
{
var id = HiveId.TryParse(content.Field(fieldAlias).ToString());
if (id.Success)
{
url = _urlHelper.GetMediaUrl(id.Result, size);
}
}
_urlHelper.DisposeIfDisposable();
return url;
}
示例2: RenderField
public IHtmlString RenderField(IRoutableRequestContext routableRequestContext, ControllerContext controllerContext, Content item,
string fieldAlias = "", string valueAlias = "", string altFieldAlias = "", string altValueAlias = "", string altText = "", string insertBefore = "", string insertAfter = "",
bool recursive = false, bool convertLineBreaks = false, bool removeParagraphTags = false,
UmbracoRenderItemCaseType casing = UmbracoRenderItemCaseType.Unchanged,
UmbracoRenderItemEncodingType encoding = UmbracoRenderItemEncodingType.Unchanged)
{
var sb = new StringBuilder();
// Handle hard coded "friendly" system keys
if (fieldAlias == "Name" || fieldAlias == "UrlName")
{
valueAlias = fieldAlias;
fieldAlias = NodeNameAttributeDefinition.AliasValue;
}
if (fieldAlias == "CurrentTemplateId")
{
fieldAlias = SelectedTemplateAttributeDefinition.AliasValue;
valueAlias = "TemplateId";
}
if (altFieldAlias == "Name" || altFieldAlias == "UrlName")
{
altValueAlias = altFieldAlias;
altFieldAlias = NodeNameAttributeDefinition.AliasValue;
}
if (altFieldAlias == "CurrentTemplateId")
{
altFieldAlias = SelectedTemplateAttributeDefinition.AliasValue;
altValueAlias = "TemplateId";
}
var val = item.Field<string>(fieldAlias, valueAlias, recursive);
if (val.IsNullOrWhiteSpace() && !altFieldAlias.IsNullOrWhiteSpace())
{
val = item.Field<string>(altFieldAlias, altValueAlias, recursive);
}
if (val.IsNullOrWhiteSpace() && !altText.IsNullOrWhiteSpace())
{
val = altText;
}
if(!val.IsNullOrWhiteSpace())
{
switch (casing)
{
case UmbracoRenderItemCaseType.Upper:
val = val.ToUpper();
break;
case UmbracoRenderItemCaseType.Lower:
val = val.ToLower();
break;
case UmbracoRenderItemCaseType.Title:
val = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(val);
break;
default:
break;
}
switch (encoding)
{
case UmbracoRenderItemEncodingType.Url:
val = HttpUtility.UrlEncode(val);
break;
case UmbracoRenderItemEncodingType.Html:
val = HttpUtility.HtmlEncode(val);
break;
default:
break;
}
if (convertLineBreaks)
{
val = val.Replace(Environment.NewLine, "<br />");
}
if (removeParagraphTags)
{
val = val.Trim().Trim("<p>").Trim("</p>");
}
sb.Append(HttpUtility.HtmlDecode(insertBefore));
sb.Append(val);
sb.Append(HttpUtility.HtmlDecode(insertAfter));
}
//now we need to parse the macro syntax out and replace it with the rendered macro content
var macroRenderer = new MacroRenderer(routableRequestContext.RegisteredComponents, routableRequestContext);
var macroParser = new MacroSyntaxParser();
IEnumerable<MacroParserResult> parseResults;
var parsed = macroParser.Parse(sb.ToString(),
(macroAlias, macroParams)
=> macroRenderer.RenderMacroAsString(macroAlias,
macroParams,
controllerContext, false,
() => item), out parseResults);
//.........这里部分代码省略.........
示例3: GetFieldValue
private static object GetFieldValue(Content item, string fieldAlias, string valueAlias, bool recursive)
{
switch (fieldAlias)
{
case "@id":
return item.Id;
case "@parentId":
return item.ParentContent().Id;
case "@name":
case "Name":
return item.Name;
case "@urlName":
case "UrlName":
return item.UrlName;
case "@path":
return item.GetPath().ToString();
case "@level":
return item.GetPath().Level;
case "@template":
return item.CurrentTemplate.Alias;
case "@templateId":
case "CurrentTemplateId":
return item.CurrentTemplate.Id;
case "@templateFileName":
return item.CurrentTemplate.Id.Value;
case "@nodeTypeAlias":
return item.ContentType.Alias;
case "@createDate":
return item.UtcCreated;
case "@updateDate":
return item.UtcModified;
case "@statusChangedDate":
return item.UtcStatusChanged;
default:
return item.Field(fieldAlias, valueAlias, recursive);
}
}