Macros creation: multiple excerpts, an option?

Wig Shire June 30, 2022

Hi, I won't go into the details of why we're still using the Data Center version and can't even afford the multi-excerpt macro... but I was considering writing my version, how difficult can it be right?

So I'm a software developer, so I know my way around web code, but I can find very little actual guidance and examples of macro creation for confluence.

Surely this has got to be a relatively easy thing to create: a pair of macros, one to create a section with a key on a page in which content can be added, and one to 'include' on another page using that key.

Any advice, help or pointers would be cool :)

(sorry, no option to select data center hosting version)

3 answers

0 votes
Wig Shire July 3, 2022

Ok, so I got it working. Not sure if its the most efficient, but seems ok.

The Multi-Excerpt doesn't really need to do anything - just be present with a parameter defining the key.

The Include Multi-Excerpt is more complicated:

  1. Loop through the space to find the specified Page which contains the excerpts
  2. Get the Page's body content as a string
  3. Locate the parameter and its name within the string, then locate the end of macro and isolate the macro body with string sub string action - this probably won't work well nesting etc.
  4. print out isolated content

Now my final problem is using this macro within another, which works fine, but when I do an Export to Word command it gives an 'Error rendering macro' error... any ideas on that one?

0 votes
Wig Shire July 1, 2022

Ok so now I'm going down the path of using the $content class to try and get to an object which allows me to get a new page, based on its title, but I've also come across

$content.class.forName('????') which could help instantiate another useful class? 

0 votes
Wig Shire July 1, 2022

So I've done the first halve (easily?) I hope, simply ask for a excerpt key parameter and add it as an 'id' property to a div enclosing the $body. Embed on a page, assign a key, add in content and checked the page source - all looks good.

The next challenge was to do the other end - the include. This is a 'no body' macro and the parameters are the key (again) AND a page reference using the 'confluence-content' parameter type. So far so good.

The plan was to get the referenced page content, parse it to extract the 'div' part with the key id and display that.

Problem now is how do I 'get the reference page content' to do the parsing - any ideas? The 'confluence-content' param type just appears to be a string...

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PERMISSIONS LEVEL
Site Admin
TAGS
AUG Leaders

Atlassian Community Events