惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

罗磊的独立博客
Recent Announcements
Recent Announcements
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
有赞技术团队
有赞技术团队
J
Java Code Geeks
T
The Blog of Author Tim Ferriss
MyScale Blog
MyScale Blog
人人都是产品经理
人人都是产品经理
aimingoo的专栏
aimingoo的专栏
U
Unit 42
The GitHub Blog
The GitHub Blog
云风的 BLOG
云风的 BLOG
T
Tailwind CSS Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - 三生石上(FineUI控件)
Apple Machine Learning Research
Apple Machine Learning Research
小众软件
小众软件
Hugging Face - Blog
Hugging Face - Blog
博客园 - 司徒正美
腾讯CDC
I
InfoQ
GbyAI
GbyAI
博客园_首页

博客园 - jerreychen

常用的JavaScript验证正则表达式 用CSS设置打印换页 使用Form认证实现用户登录 (LoginView的使用) 向容器(PlaceHolder)中动态添加多个用户控件(UserControl) C#.Net中WinForm采用Active Directory进行身份认证 Windows XP 如何设置系统自动关机任务 - jerreychen DataList嵌套GridView实现文章分类列表显示(2) visual studio 2008 sp1中如何让WebBrowser控件可编辑 - jerreychen SQLite 数据库初学 学习笔记 - jerreychen - 博客园 如何将.xsd文件自动生成对象 ASP.NET页面事件:顺序与回传详解 读取自定义的config文件 - jerreychen - 博客园 格式化数据 Net支持gzip 压缩格式 压缩与解压 .net 序列化数据对象 .net 下,日期的格式化 太久太久没来了,久违了-博客园 showModelDialog 关闭后改变GridView某个单元格的值
Umbraco 设置Document Types 的默认值
jerreychen · 2008-05-06 · via 博客园 - jerreychen

Umbraco 里面设置DocumentTypes 的时候它是没有默认值选项的
那么新建页面的时候怎么样去设置他的默认值?
DocumentType 里面 新建新的Property时候 它有个Description 让我们输入该Property的描述信息
那么现在我们就在Description里做文章了,比如:我们在Description里面输入的内容,两个'#'符号内的内容为默认值
这里我们使用Umbraco的ActionHandler接口,单当前的Action为New的时候,处理设置默认值

 1using System;
 2using System.Collections.Generic;
 3using System.Text;
 4using umbraco.cms.businesslogic.web;
 5using umbraco.interfaces;
 6using System.Text.RegularExpressions;
 7using umbraco.BusinessLogic.Actions;
 8
 9namespace 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