Sitecore 多种 RTE Class 样式
Sitecore Multiple RTE Class Styles
我可以为 RichTextEditor(RTE) 添加 CSS 样式路径,如下所示,我可以 select 在 RTE 中定义样式。
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<settings>
<setting name="WebStylesheet">
<patch:attribute name="value">/resources/customCSS.css</patch:attribute>
</setting>
</settings>
</sitecore>
</configuration>
但是,应该有两种或两种以上的CSS。
例如,角色 A 中的用户将只能看到 RTE Class 列表中的 "Role-A.css",角色 B 中的用户将只能看到 RTE [=] 中的 "Role-B.css" 25=]列表。
我该如何实现?
有没有办法过滤 class 列表中显示的 CSS 路径??
开箱即用是不可能的,但实现起来相当容易。创建一个继承自 Sitecore.Shell.Controls.RichTextEditor.EditorConfiguration
的新 class 并覆盖 SetupStylesheets()
方法:
public class EditorConfiguration : Sitecore.Shell.Controls.RichTextEditor.EditorConfiguration
{
public EditorConfiguration(Item profile) : base(profile)
{
}
protected override void SetupStylesheets()
{
// if (user = X)
this.Editor.CssFiles.Add("/path/to/custom.css");
base.SetupStylesheets();
}
}
然后将富文本配置文件设置为使用这种新的配置类型。切换到核心数据库,然后转到项目 /sitecore/system/Settings/Html Editor Profiles/Rich Text Default/Configuration Type
并将 Type
字段设置为新的 class。如果您的特定配置文件不包含 Configuration Type
项目,则复制或创建一个新项目,或者在配置中设置 "HtmlEditor.DefaultConfigurationType"。
我建议您在内容树某处的设置中定义一组 "stylesheets",而不是对样式表进行硬编码,然后使用不同角色的安全性和权限来限制对它们的读取访问。然后你可以简单地读回一个项目列表,迭代并添加它们,例如
然后在您的 SetupStylesheets()
方法中迭代项目。
protected override void SetupStylesheets()
{
var stylesheets = Sitecore.Context.ContentDatabase.GetItem("/sitecore/content/RTE-Stylesheets").Children.ToList();
foreach (var item in stylesheets)
{
this.Editor.CssFiles.Add(item["Stylesheet"]);
}
base.SetupStylesheets();
}
由于您限制了权限,因此只会返回并添加用户有权访问的样式表。
我可以为 RichTextEditor(RTE) 添加 CSS 样式路径,如下所示,我可以 select 在 RTE 中定义样式。
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<settings>
<setting name="WebStylesheet">
<patch:attribute name="value">/resources/customCSS.css</patch:attribute>
</setting>
</settings>
</sitecore>
</configuration>
但是,应该有两种或两种以上的CSS。 例如,角色 A 中的用户将只能看到 RTE Class 列表中的 "Role-A.css",角色 B 中的用户将只能看到 RTE [=] 中的 "Role-B.css" 25=]列表。
我该如何实现?
有没有办法过滤 class 列表中显示的 CSS 路径??
开箱即用是不可能的,但实现起来相当容易。创建一个继承自 Sitecore.Shell.Controls.RichTextEditor.EditorConfiguration
的新 class 并覆盖 SetupStylesheets()
方法:
public class EditorConfiguration : Sitecore.Shell.Controls.RichTextEditor.EditorConfiguration
{
public EditorConfiguration(Item profile) : base(profile)
{
}
protected override void SetupStylesheets()
{
// if (user = X)
this.Editor.CssFiles.Add("/path/to/custom.css");
base.SetupStylesheets();
}
}
然后将富文本配置文件设置为使用这种新的配置类型。切换到核心数据库,然后转到项目 /sitecore/system/Settings/Html Editor Profiles/Rich Text Default/Configuration Type
并将 Type
字段设置为新的 class。如果您的特定配置文件不包含 Configuration Type
项目,则复制或创建一个新项目,或者在配置中设置 "HtmlEditor.DefaultConfigurationType"。
我建议您在内容树某处的设置中定义一组 "stylesheets",而不是对样式表进行硬编码,然后使用不同角色的安全性和权限来限制对它们的读取访问。然后你可以简单地读回一个项目列表,迭代并添加它们,例如
然后在您的 SetupStylesheets()
方法中迭代项目。
protected override void SetupStylesheets()
{
var stylesheets = Sitecore.Context.ContentDatabase.GetItem("/sitecore/content/RTE-Stylesheets").Children.ToList();
foreach (var item in stylesheets)
{
this.Editor.CssFiles.Add(item["Stylesheet"]);
}
base.SetupStylesheets();
}
由于您限制了权限,因此只会返回并添加用户有权访问的样式表。