本文整理汇总了C#中TemplateItem类的典型用法代码示例。如果您正苦于以下问题:C# TemplateItem类的具体用法?C# TemplateItem怎么用?C# TemplateItem使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TemplateItem类属于命名空间,在下文中一共展示了TemplateItem类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ChangedTemplate
public virtual void ChangedTemplate(Item targetItem, TemplateItem oldTemplate)
{
if(oldTemplate != null)
_logger.Debug($"* [T] from {oldTemplate.Name} to {targetItem.TemplateName}");
else
_logger.Debug($"* [T] to {targetItem.TemplateName}");
}
示例2: InheritsFromTemplate
private bool InheritsFromTemplate(TemplateItem templateItem, Sitecore.Data.ID templateId)
{
return templateItem.ID == templateId
|| (templateItem.BaseTemplates != null
&& templateItem.BaseTemplates
.Where(baseTempl => InheritsFromTemplate(baseTempl, templateId)).Count() > 0);
}
示例3: FindItemsByTemplateOrDerivedTemplate
/// <summary>
/// Find items below another based on the specified template or a derived template
/// </summary>
/// <param name="rootItem">The item the item must be below</param>
/// <param name="template">The template to find item based on, or based on derivaties of the template</param>
/// <returns>All items which match</returns>
public static Item[] FindItemsByTemplateOrDerivedTemplate(this Item rootItem, TemplateItem template)
{
if (rootItem == null || template == null)
return new Item[0];
var database = rootItem.Database;
var foundItems = new List<Item>();
var derivedTemplates = new List<TemplateItem>();
var references = Sitecore.Globals.LinkDatabase.GetReferrers(template);
foreach (var reference in references)
{
var source = reference.GetSourceItem();
if (source.Template.Key == "template")
derivedTemplates.Add((TemplateItem)source);
else
{
if(source.Axes.IsDescendantOf(rootItem))
foundItems.Add(source);
}
}
foreach(var derivedTemplate in derivedTemplates)
{
foundItems.AddRange(FindItemsByTemplateOrDerivedTemplate(rootItem, derivedTemplate));
}
return foundItems.ToArray();
}
示例4: TemplateIsOrBasedOn
/// <summary>
/// Determine if an item is based on a given template or if the item's template is based on the given template
/// </summary>
/// <param name="item">The item to test the template of</param>
/// <param name="template">The template which the item's template should be or inherit from</param>
/// <returns>True if the item's template is based on the given template, otherwsie false</returns>
public static bool TemplateIsOrBasedOn(this Item item, TemplateItem template)
{
if (template != null)
return TemplateIsOrBasedOn(item, template.ID);
else
return false;
}
示例5: Check
/// <summary>Checks the specified output.</summary>
/// <param name="output">The output.</param>
/// <param name="item">The item.</param>
public override void Check(ValidationAnalyzer output, Item item)
{
Assert.ArgumentNotNull(output, "output");
Assert.ArgumentNotNull(item, "item");
var parametersTemplateId = item[ParametersTemplateFieldId];
if (string.IsNullOrEmpty(parametersTemplateId))
{
return;
}
var parameterTemplateItem = item.Database.GetItem(parametersTemplateId);
if (parameterTemplateItem == null)
{
return;
}
var template = new TemplateItem(parameterTemplateItem);
foreach (var templateFieldItem in template.Fields)
{
var templateItem = new TemplateItem(templateFieldItem.InnerItem.Parent.Parent);
if (!templateItem.BaseTemplates.Any())
{
continue;
}
output.MaxMessages++;
if (string.IsNullOrEmpty(templateFieldItem.ToolTip))
{
output.Write(SeverityLevel.Suggestion, "Parameter must have help text", string.Format("The parameter '{0}' in the '{1}' control does not have a short help text. The short help text is part of documentation and is displayed in the Documentation web site", templateFieldItem.Name, item.Name), "Write a help text.", templateFieldItem.InnerItem);
}
}
}
示例6: CustomItemInformation
public CustomItemInformation(TemplateItem template, string baseNamespace, string baseFileRoot)
{
CustomItemSettings settings = new CustomItemSettings(HttpContext.Current);
ICustomItemNamespaceProvider namespaceProvider = AssemblyUtil.GetNamespaceProvider(settings.NamespaceProvider);
ICustomItemFolderPathProvider filePathProvider = AssemblyUtil.GetFilePathProvider(settings.FilepathProvider);
GetItemInformation(template, baseNamespace, baseFileRoot, filePathProvider, namespaceProvider);
}
示例7: RecursiveCheckBaseTemplatesIfStructuredTree
/// <summary>
/// Cheks if selected templates has "StructuredData StructuredTreeArchive" as one of its base tamplates
/// </summary>
/// <param name="templateItem">The template item. </param>
/// <returns>if selected templates has "StructuredData StructuredTreeArchive".</returns>
private static bool RecursiveCheckBaseTemplatesIfStructuredTree(TemplateItem templateItem)
{
if (templateItem != null
&& !templateItem.Name.Equals("Standard template"))
{
if (templateItem.Name.Equals("StructuredData StructuredTreeArchive"))
{
return true;
}
TemplateItem[] baseTemplates = templateItem.BaseTemplates;
if (baseTemplates != null)
{
foreach (TemplateItem baseTemplateItem in baseTemplates)
{
bool success = RecursiveCheckBaseTemplatesIfStructuredTree(baseTemplateItem);
if (success)
{
return true;
}
}
}
}
return false;
}
示例8: CreateAlphabetFolderStructure
/// <summary>
/// Creates an alphabet folder structure under the passed in parent. This will also inlcude 123 as a folder
/// for handling items that start with numbers.
/// </summary>
/// <param name="parentItem">The parent item.</param>
/// <param name="folderTemplate">The folder template.</param>
/// <param name="upperCase">if set to <c>true</c> make the letter folder name upper case.</param>
public static void CreateAlphabetFolderStructure(Item parentItem, TemplateItem folderTemplate, bool upperCase)
{
if (parentItem == null || folderTemplate == null) return;
Database masterDb = Factory.GetDatabase("master");
using (new SecurityDisabler())
{
foreach (string letter in alphabetFolderNames)
{
//If we are supposed to make the folder name upper case, do so
string folderName = letter;
if (upperCase)
{
folderName = folderName.ToUpper();
}
//Only add the folder if it does not already exist, this way this method can be used to fill
// in missing folders in an already existing partial alpha folder structure.
string letterFolderPath = string.Format("{0}/{1}", parentItem.Paths.Path, folderName);
Item alphaFolder = SitecoreItemFinder.GetItem(masterDb, letterFolderPath);
if (alphaFolder == null)
{
parentItem.Add(letter.ToUpper(), folderTemplate);
}
}
}
}
示例9: Execute
public override void Execute(CommandContext context)
{
var selectedItem = context.Items.FirstOrDefault();
if (selectedItem == null)
return;
string templateId = "{CC80011D-8EAE-4BFC-84F1-67ECD0223E9E}";
TemplateItem newTemplate = new TemplateItem(Sitecore.Context.Database.GetItem(templateId));
if (newTemplate != null)
{
try
{
using (new Sitecore.SecurityModel.SecurityDisabler())
{
selectedItem.Editing.BeginEdit();
selectedItem.ChangeTemplate(newTemplate);
}
}
catch (Exception ex)
{
Log.Error(ex.Message, ex, this);
throw;
}
finally
{
selectedItem.Editing.EndEdit();
}
}
}
示例10: AddTemplate
protected void AddTemplate(ITemplate template) {
if (template != null) {
TemplateItem i = new TemplateItem();
template.InstantiateIn(i);
Controls.Add(i);
}
}
示例11: Folder
/// <summary>
/// Initializes a new instance of the <see cref="Folder"/> class.
/// </summary>
/// <param name="templateItem">The template item.</param>
/// <param name="format">The format.</param>
public Folder(TemplateItem templateItem, string format)
{
Sitecore.Diagnostics.Assert.IsNotNull(templateItem, "templateItem");
Sitecore.Diagnostics.Assert.IsNotNullOrEmpty(format, "format");
Template = templateItem;
FormatString = format;
}
示例12: Render
public override string Render(TemplateItem item)
{
return Template.Resolve().Render(new TemplateItem {
Parent = item,
Data = new ExpressionEvaluator(item).Evaluate(Data).Value,
Options = new ExpressionEvaluator(item).Evaluate(Options).Value,
});
}
示例13: RecurseTemplates
private static void RecurseTemplates(ICollection<string> list, TemplateItem template)
{
foreach (var baseTemplateItem in template.BaseTemplates)
{
list.Add(IdHelper.NormalizeGuid(baseTemplateItem.ID));
if (baseTemplateItem.ID != TemplateIDs.StandardTemplate)
RecurseTemplates(list, baseTemplateItem);
}
}
示例14: GetAllTemplates
public void GetAllTemplates(TemplateItem baseTemplate, List<string> list)
{
var str = IdHelper.NormalizeGuid(baseTemplate.ID);
list.Add(str);
if (baseTemplate.ID == TemplateIDs.StandardTemplate)
return;
foreach (var item in baseTemplate.BaseTemplates)
GetAllTemplates(item, list);
}
示例15: TemplateAndBaseCheck
protected virtual bool TemplateAndBaseCheck(TemplateItem template, ID templateId)
{
if (template.ID == templateId)
{
return true;
}
return template.BaseTemplates.Any(baseTemplate => TemplateAndBaseCheck(baseTemplate, templateId));
}