How do I create a custom macro

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?

1 answer

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):

var limitDate = new Date();
limitDate.setDate(limitDate.getDate() + 3);
jQuery("").each(function() {
var timedate = new Date(jQuery(this).attr("datetime"));
if (timedate < limitDate) {
jQuery(this).attr("style", "border:1px solid #ffab00;");
jQuery("").attr("style", "border:1px solid #ff5630;");

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

## @noparams


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?

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.

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

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.

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.

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

Thank you all!

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Feb 06, 2019 in Confluence

Try out the new editing experience

Hi team, I’m Avinoam, a product manager on Confluence Cloud, and today I’m really excited to let the Community know that all customers can now try out the new editing experience and see some of the ...

1,376 views 100 8
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you