通过CMS处理用户控件​​的内容? [英] Handle content in usercontrols through CMS?

查看:135
本文介绍了通过CMS处理用户控件​​的内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有复合C1的方式来管理,通过后端的页面中使用ASP.NET用户控件静态文本?

Is there a way in Composite C1 to manage static text in ASP.NET usercontrols used on pages through the backend?

推荐答案

在这个答案我asuming你会喜欢静态文字,以通过可视化编辑器(HTML文件)进行维护,让您的用户做标题,造型,大胆等,如果你只是一个简单的大这个文本框可以简化。

In this answer I'm asuming you would like the "static text" to be maintained via a Visual Editor (html document), allowing your users to do heading, styling, bold etc. If you are just going for a simple large textbox this can be simplified.

通过对数据的角度建立一个新的全球数据类型开始 - 命名它(code下面的示例中,我把它命名为Maw.Content),并给它这两个领域:

Start by creating a new Global Data Type on the Data perspective - name it (in the code sample below, I named it Maw.Content) and give it these two fields:


  • FieldKey 串(32)(小工具:默认的文本框)

  • FieldContent 字符串(无限)(小工具:Composite.Widgets.String.VisualXhtmlEditor)

  • FieldKey string(32) (Widget: the default TextBox)
  • FieldContent string(Unlimited) (Widget: Composite.Widgets.String.VisualXhtmlEditor)

在您保存新的数据类型,您可以添加'记录'它 - 并指定一个关键领域及相关内容。

Once you save your new data type you can add 'records' to it - and specify a field key and related content.

这应该采取管理内容的护理 - 你的UI应该是pretty用户友好。你可以右键点击该数据类型在树和使用命令中显示的内容的角度,这将让你的数据类型显示在内容|网站项目。这样,用户就不必在所有使用数据透视图。

This should take care of managing the content - the UI you get should be pretty user friendly. You can right click the data type in the tree and use the command "Show in Content perspective" which will make your data type show up on Content | Website Items. This way your users do not have to use the Data perspective at all.

考虑限制用户对数据文件夹只是编辑访问,如果你不需要用户添加/删除项目。右键单击包含数据项和编程选择编辑权限的文件夹。

Consider limiting user access to the data folder to just "Edit", in case you do not need users to add/delete items. Right click the folder containing data items and slect 'Edit Permissions'.

从指定字段输出XHTML
在你的用户控件,你可以抓住相关的具体FieldKey这样的HTML:

Outputting the XHTML from a named field In your user controls you can grab the html related to s specific FieldKey like this:

using System;
using System.Linq;
using System.Xml.Linq;
using System.Web.UI;
using Composite.Data;
using Composite.Core.Xml;

public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string fieldKey = "SomeKeyHere";
        string xhtmlString;

        using( var connection = new DataConnection())
        {
            xhtmlString = connection.Get<Maw.Content>().Where(f => f.FieldKey == fieldKey).Select(f => f.FieldContent).FirstOrDefault();
        }

        if (xhtmlString != null)
        {
            XhtmlDocument htmlDoc = XhtmlDocument.Parse(xhtmlString);
            foreach (XNode bodyNode in htmlDoc.Body.Nodes())
            {
                this.Controls.Add( new LiteralControl(bodyNode.ToString()));
            }
        }
        else
        {
            this.Controls.Add(new LiteralControl("Unknown FieldKey: " + fieldKey));            
        }

    }
}

这篇关于通过CMS处理用户控件​​的内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆