Adding current user and current date in the template in Blueprint development

Hi,

I finished simple, intermediate and advanced blueprint tutorials of the Atlassian https://developer.atlassian.com/server/confluence/tutorials-and-guides/.

Currently, I have a soy file and a js file for Blueprint wizard page; a Java file as context provider and an xml file for template.

I added the current date to the title easily. I also want to insert current date and the current user (page creator) to the page before sending user to edit. (For example; default meeting notes blueprint). However I couldn’t find how to set these values in template.

In xml template, the current date should be as following format:

<time datetime="2021-02-17"/>

So, I cannot add something like “at:var” for datetime value. So, I cannot change it from the context provider class.

Also, I tried to set this value through Javascript and JQuery, however I just can change things about the wizard page. I failed on manipulating the actual template page.

Nearly same issue with the page creator. I should add the user as following format:

<ri:user ri:userkey="2c9680f7405147ee0140514c26120003"/>

However, I couldn’t set the userkey through Java and also I couldn’t get the page creator value.

Thus;

  1. How can I add the current date to the template page?
  2. How can I add the user mention to the template page?
  3. How can I get the creator of the page?

Thanks already for all your interests.

Have a nice day!

The answer is coming from me, too.

In template’s xml, we are adding two variables for the date and the user with enabled XHTML support:

<at:var at:name="currentDate" rawxhtml=true />
<at:var at:name="currentUser" rawxhtml=true />

In the context provider class, we will set these variables with html tags:

context.put("currentDate", "<time datetime=\" + sdf.format(new Date()) + "\"/>");
context.put("currentDate", "<ri:user ri:userkey=\" + AuthenticatedUserThreadLocal.get().getKey() + "\"/>");

where the context is the context map for blueprint and sdf is the instance of SimpleDateFormat class with a pre-defined date (not date-time) format.

1 Like