首页 > 解决方案 > 在蓝图开发的模板中添加当前用户和当前日期

问题描述

我完成了 Atlassian https://developer.atlassian.com/server/confluence/tutorials-and-guides/的简单、中级和高级蓝图教程。

目前,我有一个用于蓝图向导页面的 soy 文件和一个 js 文件;一个 Java 文件作为上下文提供者,一个 xml 文件作为模板。

我很容易将当前日期添加到标题中。我还想在发送用户进行编辑之前将当前日期当前用户(页面创建者)插入页面。(例如;默认会议记录蓝图)。但是我找不到如何在模板中设置这些值。

在 xml 模板中,当前日期应为以下格式:

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

所以,我不能为日期时间值添加类似“<at:var>”的东西。所以,我不能从上下文提供者类中改变它。

此外,我尝试通过 Javascript 和 JQuery 设置此值,但是我只能更改有关向导页面的内容。我未能操作实际的模板页面。

页面创建者的问题几乎相同。我应该按以下格式添加用户:

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

但是,我无法通过 Java 设置用户密钥,也无法获取页面创建者值。

因此;

  1. 如何将当前日期添加到模板页面?
  2. 如何将用户提及添加到模板页面?
  3. 如何获取页面的创建者?

已经感谢您的所有兴趣。

祝你今天过得愉快!

标签: confluence

解决方案


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.


推荐阅读