Macros not complete

Enonic version: 6.6.0

Hi! I’m trying to create a set of new macros to share across projects and I see some issues to have this working fine. First, a macro can’t hold the “HtmlArea” input type, so, if I want to get a styled box containing a text, it won’t work, and if I add this element type, it is rendered as an ugly and simple “TextArea” element, as you can see on the attached picture:

Also, I can’t use “Item Sets”. Suposing I want to create an accordion element, that will handle some sets of Title (which is shown when the accordion is collapsed) and Content (to show when expanded). If I set the minimum occurencies to 0, the button to “Add Expandere Element” is show, but without any action when clicking on it.

But, if I set this minimum occurencies to 1 or more, this is the how the macro editor behave:

Any tips on how to solve this or if there’s a estimated time to solve this issue?

20CharactersJustToUp

1 Like

Currently we don’t support item sets in the macro form. I’m not sure we are going to support them.

Also HtmlArea inside a macro would be problematic, since the HtmlArea can again use macros.

Can you paste your macro descriptor (XML) with the form you are using, to get a better idea of what you are trying to do?

The reason why item sets or other kind of hierarchical structures do not work, is that the macro is serialized as a set of key-value pairs. See examples here: http://xp.readthedocs.io/en/stable/developer/site/macros/index.html

[macroname attrib1="value1" attrib2="value2"] body [/macroname]

The Macro Dialog is just a UI helper to generate and insert that string in the HtmlArea.

But I see we need to improve the documentation and explain the form elements that are not allowed in macro forms (e.g. HtmlArea, item-sets).

1 Like

<macro> <display-name>Box</display-name> <description>Info notification panel</description> <form> <item-set name="accordionGroup"> <label>Ekspanderende gruppe</label> <occurrences minimum="0" maximum="0"/> <items> <item-set name="accordions"> <label>Ekspanderende element</label> <occurrences minimum="0" maximum="0"/> <items> <input type="TextLine" name="title"> <label>Tittel</label> <occurrences minimum="0" maximum="1"/> </input> <input type="HtmlArea" name="content"> <label>Innhold</label> <occurrences minimum="0" maximum="1"/> </input> </items> </item-set> </items> </item-set> </form> </macro>


This should be used to render an accordion group on the frontend. We achieve this using shortcodes and we have been using since 6.5.2 :stuck_out_tongue: Just placing {{ACCORDION1}} or the order of the group we want to show in the article body, we replace the tag with the content on the group and then thymeleaf renders it.

Ok, I understand, but that is not going to work with macros.

What about creating a part component with the same logic and having the same config in the part form? You can then configure the accordion in Live Edit.

This is what we do, but even we want to use, the accordion mixin should be present. With macros, we could have this globally and use always we need. :slight_smile:

Hello.

I worked a bit with macros and i would really like to see it be improved.

Some use cases which have room for improvements:

  1. Authors want a fact-box inside an article.
    You could as mentioned use a part and add it in the live edit, but this doesnt allow you to add it mid-text, and it also wouldn’t be searchable when doing an article search.

Macros seems to solve both these issues, but there are some drawbacks. Firstly, you cannot use a HTMLArea, which means you probably want to create this as a body. The problem with this is that it now displays an empty popup, both the preview and config is unused. In addition it only leaves a [facts /] tag in the HTMLArea of the article, leaving the author in charge of properly formatting the macro.

I can see the macro inside macro issue, but nothing is currently stopping you from doing that manually either - and to be honest, maybe it should actually just work.

  1. Authors want a gallery inside an article.
    For the same reasons as previously mentioned, this could be better with a macro than a part.

The problem here is that Item Sets do not work and it makes it harder to make a gallery with alt/credit/figcaption fields.

I also want to add that the HTMLArea macro tag could look nicer than [macro]-format. Maybe a placeholder macro wrapper would be better and rather have the [macro]-format in source code?

TLDR;
It would be good for HTMLArea and ItemSets to work in macros.

The problem here is really serializing item-sets in macros. The idea is that you should be able to type macro’s directly into the editor.

I guess the body element has some potential for complex values though?

Yes, the body element does work as a single “HTMLArea”. But as i said it leaves it up to the editor to properly format it, since macros are always outputted self-closed.

Does it have to be serialized though? Could it be stored as a JSON in the back, and previewed in the editor as it would look when rendered? Then you could click it to edit macro

Concept with macros is really to enable editing it without using the insert dialogue at all. I guess we have to investigate this further. I guess it would be cool to be able to insert any part as a macro too, and store the part config outside of the html?

This is what we do now on our team’s projects. We store macro content as mixins item sets and the macros are used just as shortcuts to these values.

Really don’t understand what you mean? Screenshot?

For example: we have a gallery mixin where the user can set up multiples item sets with images and a macro that places “[bildeserie id=”(0-9)"]" where the parameter “id” is the order of the images gallery.