通过 CMS 处理用户控件中的内容?

发布于 2024-12-18 07:53:10 字数 62 浏览 3 评论 0原文

Composite C1 中是否有一种方法可以通过后端管理页面上使用的 ASP.NET 用户控件中的静态文本?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦断已成空 2024-12-25 07:53:10

在这个答案中,我假设您希望通过可视化编辑器(html 文档)维护“静态文本”,允许您的用户执行标题、样式、粗体等。如果您只是想要一个简单的大文本框,那么可以简化。

首先在数据透视图上创建一个新的全局数据类型 - 为其命名(在下面的代码示例中,我将其命名为 Maw.Content)并为其提供以下两个字段:

  • FieldKey string(32) (Widget : 默认文本框)
  • FieldContent string(Unlimited) (Widget: Composite.Widgets.String.VisualXhtmlEditor)

保存新数据类型后,您可以向其中添加“记录” - 并指定字段键和相关内容。

这应该负责管理内容 - 您获得的 UI 应该非常用户友好。您可以右键单击树中的数据类型,然后使用命令“在内容透视图中显示”,这将使您的数据类型显示在内容 |网站项目。这样您的用户就根本不必使用数据透视图。

如果您不需要用户添加/删除项目,请考虑将用户对数据文件夹的访问权限限制为“编辑”。右键单击包含数据项的文件夹并选择“编辑权限”。

从命名字段输出 XHTML
在您的用户控件中,您可以获取与特定 FieldKey 相关的 html,如下所示:

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));            
        }

    }
}

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.

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 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.

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'.

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));            
        }

    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文