Something like "quick parts" or "mini templates" in the WYSIWYG Editor?

Hello,

Is there a function to make something like Quick Parts (known from MS Word to insert chunks of text / content)?

I want to help our users with “mini templates” that contain larger chunks of content, users should be able to select them as easily as a macro but I want them to be able to edit the stuff via the WYSIWYG Editor afterwards.

When I hardcode the desired content in the macro users can’t edit it.

Currently we really like a few XWiki Templates and user can edit them, but the boxes and other stuff in the created pages are quite complicated and can’t be manually achieved via the WYSIWYG Editor. Even if that would be possible, then every user would probably make something that looks a bit different.

If users use the XWiki templates that contains complicated stuff, this brings the issue that if they break things, they can’t repair this stuff. Also these complicated things in the normal templates can’t be added to already existent pages with the WYSIWYG Editor.

If possible, it should simply copy the content of the “quick part” / “mini template” on the current cursor position in WYSIWYG.

For example I want to provide this for our users:

{{box cssClass="floatinginfobox" image="PLACEHOLDER" width="30%" title="**Boxtitle**"}}
|=more information |[[Link>>https://example.com]]
|=also relevant|[[Page>>doc:something.something.something.WebHome]]
{{/box}}

Users then should be able to simply edit the text, tables and stuff in WYSIWYG editor and also normally interact with the box macro settings to change the image name and so on.

Macros seems the right approach for this. Users can edit macro content. Maybe you didn’t make your macro inline editable and not with the right content type? See also https://www.xwiki.org/xwiki/bin/view/Documentation/DevGuide/Tutorials/WritingMacros/WikiMacroTutorial/#HWYSIWYGeditingofmacrocontentorparameter

Do you mean like this?
image
Because then when inserting the macro it is just empty.

Ok I figured it out what you meant, my previous post was of course a completely wrong approach.

Macrocode:

{{box cssClass="floatinginfobox" image="PLACEHOLDER" width="30%" title="**Boxtitle**"}}
|=more information |[[Link>>https://example.com]]
|=also relevant|[[Page>>doc:something.something.something.WebHome]]

{{wikimacrocontent/}}
{{/box}}

Results in this:
image

I can WYSIWYG edit inside the box but cannot edit the box macro itself because it is part of the macro script and not the content.

Is it possible to manipulate (fill) macro content with the velocity code inside the macro?
$wikimacro.content is the variable for the macro content in velocity, however #set($wikimacro.content = "Test") won’t fill the macro content with “Test”.
If macros can manipulate their own content, I could test if the content is empty and if so fill itself with the desired initial template-content.

However with the macro approach there would always be an additional layer in it, the desired content would always be inside another thing.
Preferable it would be an initial set of plain/clean inserted XWiki Syntax content that gets inserted and after that have no connection to the origin itself.
Just like pages that got created with real templates are simply copies and have no connection to the template after their creation.

Or another approach: Is it possible to create an macro that inserts XWiki Syntax code outside of its {{OwnMacro}}{{/OwnMacro}} block and then deletes itself?

Apparently macros can’t update their own content so that approach of the macro content filling itself with the initial template-content won’t work.
Allow wiki macros to update their contents and parameters upon execution - Development - XWiki Forum

So I have absolutely no Idea how to give a macro an initial (template like) content that users can edit after that.

Every part of the “template” that should be editable could be a parameter. Still not the same, just a suggestion how you could achieve something a bit similar and this could, e.g., be an option to expose the parameters of the box that you want your users to modify. For parameters, you can also set a default value which should work much more like what you desire. For the content, that’s unfortunately not that easy in wiki macros to have a default content, I think this is only easily possible with macros defined in Java.

Another way how you could define such “mini templates” is using editor customizations. For example, here is an example how you can add buttons to the editor that allow you to specify parameters and content. Your example should be easily adaptable to such a button. In the same way, you can also add custom quick actions using the configuration.

If you need more than just a simple macro call, you could create custom actions in the editor and buttons/quick actions for them. It should also be possible to have a more generic action that just inserts the content of a wiki page at the current position, similar to how the office import action imports a document at the position of the cursor.

1 Like

Thank you!!! They way you described with the Editor customisation combined with simply inserting the content of a wiki page is exactly what we are searching.

I now successfully created an dedicated button that inserts an placeholder Box with the predefined desired complex layout.
The limitation is, that apparently only one button per macro type can exists. So two buttons which creates differently predefined boxes (both with name: ‘box’) are not possible.

more generic action that just inserts the content of a wiki page at the current position

This is probably the most perfect way, I’ll try to find out how the office import extension does that and hopefully from that I can figure it out. If I am successful, I’ll post here how I did it.

Sidenote: I personally think that this type of mini templates could possibly be an very good benefit for all XWiki users, just like “Quick Parts” is an valued feature of Microsoft Word and Outlook.

Are you sure about that? This doesn’t seem impossible, it just seems a bit surprising. Did you try specifying different values for commandId?

This probably involves fetching the content of the page using something like /xwiki/bin/view/Sandbox/?xpage=plain&outputSyntax=annotatedhtml&outputSyntaxVersion=5.0 (construct the URL using getURL) and then inserting that HTML and then somehow initializing the CKEditor widgets on that new HTML. I don’t know enough about CKEditor to be able to give you more hints without spending a lot more time digging into the code but maybe @mleduc or @mflorea could give you a hint. I personally think such a feature would be a great addition to XWiki, if not in the core itself then definitely as an extension.

I just had a short look at the code and to me, it really seems that commandId needs to be unique but that apart from that there is no problem having several buttons for a single macro. The default for commandId is 'xwiki-macro-' + definition.macroCall.name which would explain why you had problems adding several buttons for the same macro.

1 Like

I’ve started Quick Parts feature? to discuss it.

1 Like