0
我正在嘗試構建一個簡單的「用戶模板」系統,以便我的用戶可以編輯RSS提要項目和系統生成的電子郵件的佈局,而不會混淆視圖文件等。這是我使用的內容替換字符串的標籤功能:用簡單模板系統中的內容替換標籤
private const string URL_TAG_REGEX = @"{{(?<TagName>\w*)}}";
private static string ReplaceTags(string content,
Dictionary<string, object> values) {
Regex r = new Regex(UT_TAG_REGEX);
foreach (string tag in values.Keys) {
content = r.Replace(content,
m => (m.Groups["TagName"].Value == tag ?
values[tag].ToString() : string.Empty));
}
return content;
}
我的測試模板看起來是這樣的:
<a href="{{link}}">{{title}}</a> - {{date}}<br />
{{description}}
,並正在與此渲染:
<%= UserTemplates.Render("overview_rss_item", new {
link = item.Link,
title = item.Title,
date = item.PublishDate,
description = item.Description
}) %>
Render方法負責打開文件並將匿名對象轉換爲字典。它主要工作,除了只有{{link}}標籤被匹配。其餘的正在被string.Empty取代。
你是什麼實際問題? – Morendil 2009-02-12 20:55:42