我在 Magnolia 中使用富文本字段,并为我的 CK 编辑器自定义配置:
var VAADIN_DIR_URL =
typeof CKEDITOR.vaadinDirUrl !== "undefined"
? CKEDITOR.vaadinDirUrl
: "../../../";
// Loads magnoliaFileBrowser replacing CKEditor file browser. This is added to the custom config below at config.extraPlugins
CKEDITOR.plugins.addExternal(
"magnoliaFileBrowser",
VAADIN_DIR_URL + "js/filebrowser/"
);
CKEDITOR.editorConfig = function (config) {
// MIRROR info.magnolia.ui.field.RichTextFieldDefinition
definition = {
alignment: true,
images: true,
lists: true,
source: false,
tables: true,
colors: null,
fonts: null,
fontSizes: null,
};
// MIRROR info.magnolia.ui.field.RichTextFieldDefinition
removePlugins = [];
// CONFIGURATION FROM DEFINITION
if (!definition.alignment) {
removePlugins.push("justify");
}
if (!definition.images) {
removePlugins.push("image");
}
if (!definition.lists) {
// In CKEditor 4.1.1 enterkey depends on indent which itself depends on list
removePlugins.push("enterkey");
removePlugins.push("indent");
removePlugins.push("list");
}
if (!definition.source) {
removePlugins.push("sourcearea");
}
if (!definition.tables) {
removePlugins.push("table");
removePlugins.push("tabletools");
}
if (definition.colors != null) {
config.colorButton_colors = definition.colors;
config.colorButton_enableMore = false;
removePlugins.push("colordialog");
} else {
removePlugins.push("colorbutton");
removePlugins.push("colordialog");
}
if (definition.fonts != null) {
config.font_names = definition.fonts;
} else {
config.removeButtons = "Font";
}
if (definition.fontSizes != null) {
config.fontSize_sizes = definition.fontSizes;
} else {
config.removeButtons = "FontSize";
}
if (definition.fonts == null && definition.fontSizes == null) {
removePlugins.push("font");
removePlugins.push("fontSize");
}
// magnolialink AND REMOVAL OF elementspath FROM DEFAULT RICH TEXT FIELD FACTORY
removePlugins.push("elementspath");
removePlugins.push("filebrowser");
config.removePlugins = removePlugins.join(",");
config.extraPlugins = "magnolialink,magnoliaexpand,magnoliaFileBrowser";
config.format_tags = "p;h3;h4;h5;h6";
config.baseFloatZIndex = 150;
config.resize_enabled = false;
config.toolbar = "Magnolia";
config.toolbar_Magnolia = [
{ name: "clipboard", items: ["Cut", "Copy", "Paste", "-", "Undo", "Redo"] },
{
name: "links",
items: ["Link", "Unlink"],
},
{ name: "insert", items: ["SpecialChar", "Table"] },
{ name: "view", items: ["Expand"] },
"/",
{ name: "styles", items: ["Format"] },
{
name: "basicstyles",
items: ["Bold", "Italic", "Strike", "-", "RemoveFormat"],
},
{
name: "paragraph",
items: ["NumberedList", "BulletedList", "-", "Outdent", "Indent", "-"],
},
];
};
和他们的文章一样。 问题是,当我想从富文本链接到内部页面时,路径插入不正确。而是插入整个模板字符串:
${link:{uuid:{85022590-ab39-4de7-a7d5-56e48969d85f},repository:{website},path:{/linked-page}}}
实际上我想链接到模板字符串中的页面作为路径
/linked-page
。但它将整个模板字符串插入锚标记的 href 中。当我想插入来自 dam 的图像时,也会发生同样的情况。
您看到的是由 magnolia 存储的 url 模式,其中包括您检索资源的路径以及 uuid,因此即使它四处移动也可以找到它。当字段的内容被呈现或者如果/当您通过交付端点检索它时,此模式将被简单的 uri 替换。
或者,您可以(在 Java 中)通过调用
info.magnolia.link.LinkUtil#parseUUIDLink
方法将模式解析为 url。
您可能错过了链接的解析。以下内容适用于页面和图像链接。
如果您使用无头方法,您必须解析 RichText 字段的内容。在经典页面渲染(.ftl)中有相应的模板函数.