本文整理汇总了C#中Database.GetTemplate方法的典型用法代码示例。如果您正苦于以下问题:C# Database.GetTemplate方法的具体用法?C# Database.GetTemplate怎么用?C# Database.GetTemplate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Database
的用法示例。
在下文中一共展示了Database.GetTemplate方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetFieldsOfASublayoutItem
public static List<Item> GetFieldsOfASublayoutItem(Item item, Database database)
{
List<Item> sourceField = new List<Item>();
if (!string.IsNullOrEmpty(item["Datasource Template"]))
{
var firstTemplateID = database.GetItem(item["Datasource Template"]).ID;
if (!firstTemplateID.IsNull)
{
List<TemplateItem> templateItems = new List<TemplateItem>();
var firstTemplate = database.GetTemplate(firstTemplateID);
if (firstTemplate != null)
{
templateItems.Add(firstTemplate);
templateItems.AddRange(firstTemplate.BaseTemplates);
foreach (Item template in templateItems)
{
var sections =
template.Children.Where(
o => o.TemplateID.Equals(new ID("{E269FBB5-3750-427A-9149-7AA950B49301}")));
foreach (var section in sections.Distinct(new ItemEqualityComparer()))
{
foreach (Item fieldItem in section.Children.Where(o => !o.Name.StartsWith("__")))
{
sourceField.Add(fieldItem);
}
}
}
}
}
}
return sourceField;
}
示例2: RetrieveFieldItem
private static List<Item> RetrieveFieldItem(Database database, ID templateId)
{
List<Item> sourceField = new List<Item>();
List<TemplateItem> templateItems = new List<TemplateItem>();
// We retrieve him as a TemplateItem
var firstTemplate = database.GetTemplate(templateId);
if (firstTemplate != null)
{
// We add to the list the firstTemplate and his BaseTemplate to retrieve all the field.
templateItems.Add(firstTemplate);
templateItems.AddRange(firstTemplate.BaseTemplates);
foreach (Item template in templateItems)
{
//We retrieve each section
var sections =
template.Children.Where(
o => o.TemplateID.Equals(Constants.TemplateSectionsID));
// Foreach sections, we will take the field except the standard field ("__")
foreach (var section in sections.Distinct(new ItemEqualityComparer()))
{
foreach (Item fieldItem in section.Children.Where(o => !o.Name.StartsWith("__") && TextFieldTypes.Contains(o[Constants.TypeFieldID])))
{
sourceField.Add(fieldItem);
}
}
}
}
return sourceField;
}
示例3: GetAllBlogs
/// <summary>
/// Gets all the blogs.
/// </summary>
/// <param name="database">The database to get the blogs from. If null, use the context database</param>
/// <returns>The list of all blogs</returns>
public Items.WeBlog.BlogHomeItem[] GetAllBlogs(Database database)
{
if (database == null)
database = Context.Database;
// TODO: Store the result of this call in cache and clear it from cache on publish
var blogTemplate = database.GetTemplate(Settings.BlogTemplateIDString);
var contentRoot = database.GetItem(Settings.ContentRootPath);
var blogItems = contentRoot.FindItemsByTemplateOrDerivedTemplate(blogTemplate);
return (from item in blogItems select new BlogHomeItem(item)).ToArray();
}
示例4: GetAllBlogs
/// <summary>
/// Gets all the blogs.
/// </summary>
/// <param name="database">The database to get the blogs from. If null, use the context database</param>
/// <returns>The list of all blogs</returns>
public BlogHomeItem[] GetAllBlogs(Database database = null)
{
if (database == null)
database = Context.Database;
var contentRoot = database.GetItem(Settings.ContentRootPath);
return (from templateId in Settings.BlogTemplateIds
let template = database.GetTemplate(templateId)
let blogItems = contentRoot.FindItemsByTemplateOrDerivedTemplate(template)
from item in blogItems
where item != null
select new BlogHomeItem(item)).ToArray();
}
示例5: IsTemplateBucketable
/// <summary>
/// Based off a Template ID, when an Item is Created, Will it be bucketed.
/// </summary>
/// <returns>If true then it is going to be bucketed</returns>
/// <param name="templateId">Template Id</param>
/// <param name="database">Context Database</param>
public static bool IsTemplateBucketable(ID templateId, Database database)
{
#if NET40
Contract.Requires(templateId.IsNotNull());
Contract.Requires(database.IsNotNull());
#else
Assert.ArgumentNotNull(templateId, "templateId");
Assert.ArgumentNotNull(database, "database");
#endif
var template = database.GetTemplate(templateId);
if (template == null)
{
var item = database.GetItem(templateId);
if (item != null)
template = item.Template;
}
return template == null ? false : template.IsBucketTemplateCheck();
}
示例6: IsTemplateBucketable
/// <summary>
/// Based off a Template ID, when an Item is Created, Will it be bucketed.
/// </summary>
/// <returns>If true then it is going to be bucketed</returns>
/// <param name="templateId">Template Id</param>
/// <param name="database">Context Database</param>
public static bool IsTemplateBucketable(ID templateId, Database database)
{
Contract.Requires(templateId.IsNotNull());
Contract.Requires(database.IsNotNull());
var template = database.GetTemplate(templateId).IsNull() ? database.GetItem(templateId).Template : database.GetTemplate(templateId);
return template.IsBucketTemplateCheck();
}
示例7: IsTemplateBucketable
/// <summary>
/// Based off a Template ID, when an Item is Created, Will it be bucketed.
/// </summary>
/// <returns>If true then it is going to be bucketed</returns>
/// <param name="templateId">Template Id</param>
/// <param name="database">Context Database</param>
public static bool IsTemplateBucketable(ID templateId, Database database)
{
var template = database.GetTemplate(templateId).IsNull() ? database.GetItem(templateId).Template : database.GetTemplate(templateId);
return template.IsBucketTemplateCheck();
}