How do I create a custom macro

Zavery Jones January 23, 2018

I don't think I have much access to Confluence other than editing pages. I have a table that has a bunch of dates listed in it. The dates represent when our SSL certficates, for various websites, expire. I would like to have something that highlights dates (in the table) that are close to the current date.

Would this need to be a macro or something else? If it's a macro then how do I go about adding a custom macro and what kind of access do I need in order to do this?

2 answers

0 votes
Victor Prasad July 7, 2020

Hello,

Am I able to export a custom macro to another Confluence Environment or do I have to recreate it in the same one?

 

Thanks,

 

V

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 7, 2020

There's no macro export/import beyond a simple "copy and paste" of the main text, and manually copying the rest of the settings.

0 votes
Stephen Deutsch
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 23, 2018

Hi Zavery,

You would probably need to be a Confluence administrator to create any sort of customizations as far as that is concerned (unless your administrator has activated the HTML macro). Here's some options:

  1. Just doing Javascript? You could insert it into the Custom HTML in the General Settings.
  2. You could activate Javascript for a single page by using the HTML macro and inserting the script inside it.
  3. You could create a user macro that has code inside it (allows both Apache Velocity code and HTML/Javascript).

Here is some sample Javascript code that probably would do what you want. This code highlights dates that are within 3 days of today in yellow and days that are past the current date in red (you can change the number of days by changing the number 3 below):

<script>
var limitDate = new Date();
limitDate.setDate(limitDate.getDate() + 3);
jQuery("time.date-upcoming").each(function() {
var timedate = new Date(jQuery(this).attr("datetime"));
if (timedate < limitDate) {
jQuery(this).attr("style", "border:1px solid #ffab00;");
}
});
jQuery("time.date-past").attr("style", "border:1px solid #ff5630;");
</script>

If you're going to insert it as a user macro, then you'll need to include the following line at the top:

## @noparams

 

Zavery Jones January 23, 2018

Thanks for the info Stephen. I guess I'll probably need to go with Javascript.

I'm thinking we need to just do this for a single page. In this case, would an administrator be able to activate Javascript for a single page? If so, then how would they do this?

Stephen Deutsch
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 24, 2018

Hi Zavery,

for one single page, probably the best option is to use the User Macro (unless your administrator has enabled the HTML macro, in which case that is the easiest). For a user macro, they'll need to choose a name, choose whether it is viewable by all users or only the administrator (in which case they would have to add the macro to your page), and then in the template box they should insert 

## @noparams

on the first line and then the rest should be the code above. Once the user macro is inserted into the page (just like any other macro), then the changes should take effect.

Like Brian Baxter likes this
Zavery Jones January 24, 2018

Would enabling a user macro cause a security vulnerability? If so, then I may not want to do this.

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 24, 2018

It could, if malicious code was added into it, or it enabled a user to embed malicious content in the body of the macro.

Only admins can add user macros, so you have to trust your admins not to write macros that do those things.

Like Dave Liao likes this
Stephen Deutsch
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 24, 2018

Indeed, as Nic said, enabling the HTML macro could be a security vulnerability, but a user macro will only run the code that an admin has entered into it.

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 24, 2018

Yes, the risk with the html macro is wider - anyone with "edit" could inject malicious code, not just your admins.

Zavery Jones January 25, 2018

Thank you all!

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events