我可以为RichTextEditor(RTE)添加CSS样式路径,如下所示,我可以在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>
Run Code Online (Sandbox Code Playgroud)
但是,应该有两种或更多类型的CSS.例如,Role-A中的用户将只能在RTE类列表中看到"Role-A.css",而Role-B中的用户将只能在RTE类列表中看到"Role-B.css" .
我该如何实现呢?
有没有办法过滤类列表中显示的CSS路径?
它不可能开箱即用,但它很容易实现.创建一个继承Sitecore.Shell.Controls.RichTextEditor.EditorConfiguration并覆盖该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();
}
}
Run Code Online (Sandbox Code Playgroud)
然后设置富文本配置文件以使用此新配置类型.切换到核心数据库,然后转到Item /sitecore/system/Settings/Html Editor Profiles/Rich Text Default/Configuration Type并将该Type字段设置为新类.如果您的特定配置文件不包含Configuration Type项目,则复制或创建新项目,或在配置中设置"HtmlEditor.DefaultConfigurationType".
我建议您在内容树中的某些设置中定义一组"样式表",然后使用不同角色的安全性和权限限制对它们的读取权限,而不是对样式表进行硬编码.然后你可以简单地回读一个项目列表,迭代并添加它们,例如

然后迭代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();
}
Run Code Online (Sandbox Code Playgroud)
由于您使用权限进行限制,因此只返回用户有权访问的样式表,然后添加.
| 归档时间: |
|
| 查看次数: |
618 次 |
| 最近记录: |