Hi, I'm writing a user macro that will be used multiple times on a page and that will store data unique to the macro instance on the page. My idea was to use the new REST-properties API to store the data and retrieve it using JavaScript - to distinguish the data I want to use the macro-id
I can get the page id using $content.getIdAsString()
but I'm unable to find a method to get the macro-id.
There is a Class MacroDefinition in the API can I use this in the User Macro? How do I do it? I'm not sure how to do it in a User Macro.
Community moderators have prevented the ability to post new answers.
Hi Martin,
I do not see reliable way to get and persist ids for a User Macro. You can try some tricks with JavaScript: Store macro configs through REST-properties API under pageId key + counter. Where counter is handled/kept through JavaScript/HTML. Bodies of you templates are processed one by one when a page is rendered in a browser. So you can JavaScript that checks for some JavaScript variable (e.g. myUniguqMacroCounter) and if it's undefined you assume that it's a first instance for the current page and assign myUniguqMacroCounter = 1 and set some attribute in a HTML dom element for this macro instance. The second instance finds that myUniguqMacroCounter is already defined and add +1 and again store this in its bode and so on. Each of the instances tries to retrieve properties stored under key "pageId + myUniguqMacroCounter" and stores the config under this key.
But this does NOT look reliable and too much JavaScript tricks. I suggest you to convert to the "real macro".
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.