

























Umbraco 里面设置DocumentTypes 的时候它是没有默认值选项的
那么新建页面的时候怎么样去设置他的默认值?
DocumentType 里面 新建新的Property时候 它有个Description 让我们输入该Property的描述信息
那么现在我们就在Description里做文章了,比如:我们在Description里面输入的内容,两个'#'符号内的内容为默认值
这里我们使用Umbraco的ActionHandler接口,单当前的Action为New的时候,处理设置默认值
1
using System;
2
using System.Collections.Generic;
3
using System.Text;
4
using umbraco.cms.businesslogic.web;
5
using umbraco.interfaces;
6
using System.Text.RegularExpressions;
7
using umbraco.BusinessLogic.Actions;
8
9
namespace BetterTrades.CMS.UmbracoPlugins
10
{
11
public class SetDefaultValueHandler : IActionHandler
12
{
13
IActionHandler Members
27
28
public bool Execute(Document documentObject, IAction action)
29
{
30
foreach (umbraco.cms.businesslogic.property.Property Uproperty in documentObject.getProperties)
31
{
32
if (!string.IsNullOrEmpty(Uproperty.PropertyType.Description))
33
{
34
try
35
{
36
object obj = GetDefaultValue(Uproperty.PropertyType.Description);
37
if (Uproperty.PropertyType.DataTypeDefinition.DataType.DataTypeName == "True/False (Ja/Nej)")
38
Uproperty.Value = Convert.ToBoolean(obj);
39
else
40
Uproperty.Value = obj;
41
}
42
catch
43
{ }
44
}
45
}
46
return true;
47
}
48
49
object GetDefaultValue(string content)
50
{
51
Regex regex = new Regex(@"#(?<value>.*)#", RegexOptions.Compiled | RegexOptions.ExplicitCapture | RegexOptions.Singleline);
52
Match match = regex.Match(content);
53
54
return match.Groups["value"].Value;
55
}
56
57
}
58
}
59
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。