XWIKI APPWITHINMINUTES添加自定义速度脚本显示

发布于 2025-01-30 14:09:40 字数 1078 浏览 3 评论 0原文

我是Xwiki的新手,也不是Java开发人员。我想开发一个简单的AppWithinMinutes应用程序(让我们称其为ServerCatalog),以使用其属性(例如OS,环境等)的服务器列表。这都是可行的。我可以从AppWithinminites UI开发它。
我还开发了一个宏,该宏列出了标签所有页面。

例如,例如,当某人在我的ServerCatalog中创建一个条目Say Server d 56其中 d 代表开发环境。
当我们显示该条目时,我还想执行我开发的宏,以便它可以列出与标签服务器 x 56的所有页面。
请注意,我用 d x ,所以在执行宏之前,我想操纵该页面标题并删除环境前缀(在这种情况下为 d 开发环境) x

我希望这清楚我想完成的工作。请让我知道是否不清楚。

如果有人可以帮助我这样做,我将真正感谢。

编辑:
正如爱德华·莫拉鲁(Eduard Moraru)所建议的那样,我尝试了以下内容:

我创建了一个称为“ PagelistByTag”的自定义宏。 由于Python对字符串操作具有更多的控制权,因此我在ServerCatalogSheet的末尾补充说,

.
.
.
.
{{/html}}
{{/velocity}}


{{python}}
title = document.getTitle()
newTitle = title[:6] + "X" + title[6+1:]
print(newTitle)
{{/python}}

它有几个问题。.

  1. 我的HTML标签已经结束。我不能再注入任何新内容,
  2. 我不能在速度标签中添加python代码,因为xwiki不允许嵌套脚本,
  3. 我想使用python,我仍然不知道如何在python代码中调用我的宏

如果 我可以使用速度在字符串中替换第六个字符,然后一切都起作用。我可以在速度脚本内使用宏,因为它在HTML边界内。

I am new to XWiki and not a Java Developer. I would like to develop a simple AppWithinMinutes app (Let us call it ServerCatalog) for a list of servers with their properties like OS, Environment, etc.. That is all doable. I can develop that from AppWithinMinites UI.
I also have developed a macro which lists all pages by tags.

Now for example, when Someone creates an entry in my ServerCatalog say SERVERD56 Where D stands for Development environment.
when we display that Entry, I also want to execute my macro that I developed so that it can list all pages that matches the tag SERVERX56.
Note that I replaced D with X So before executing macro, I want to manipulate that page title and remove Environment prefix (in this case D for Development Environment) with X.

I hope it is clear of what I want to accomplish. Please let me know if it is unclear.

If someone can assist me on doing it, I will truly appreciate that.

EDITS:
As suggested by Eduard Moraru, I tried following things:

I have created a custom macro called "PageListByTag".
Since python has more control over string operations, I added following at the end of ServerCatalogSheet

.
.
.
.
{{/html}}
{{/velocity}}


{{python}}
title = document.getTitle()
newTitle = title[:6] + "X" + title[6+1:]
print(newTitle)
{{/python}}

There are several problems with it..

  1. my html tag is already ended. I can't inject any new content in it anymore
  2. I can't add python code inside velocity tags as nested scripting is not allowed by XWiki
  3. I still don't know how to call my macro inside python code if I want to use python

If I can replace 6th character in a string using velocity, then everything works. I can use macro inside velocity script since it is within that html boundaries.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

神妖 2025-02-06 14:09:40

据我了解,您要自定义显示应用程序条目时使用的应用程序的“表”。

如果您有关于自定义的文档部分,则可以在应该查找的位置获得很多起点:

https://extensions.xwiki.org/xwiki/xwiki/bin/bin/bin/bin/view/extension/eppension/app%20within%20within%20within%20minutes%20minutes%20minutes%20applicatimplication#hcustlication#hcustlication#hcustomization>

%20WITHIN%20分钟% 20 有趣(但也有关Xwiki应用程序如何工作的上述链接):

用于显示和编辑应用程序条目(例如HolidaySheet)

的表格

在您的情况下,它是自定义的文档(编辑Wiki语法模式)应为server> servercatalog.code.code.code.servercatalogshogsheet < /代码>

在该文档内部,您拥有AWM自动生成的代码,您可以将呼叫添加到宏中。

## AWM generated code...
...

## Customization:
{{displayAssociatedPages /}}

然后,在此宏内部(称为displayAssociatedPages,在此示例中),您可以执行以下操作:

{{velocity}}
#set ($title = $doc.title)
## OR #set ($title = $doc.name), depending if your pages have titles

#if ($title.startsWith('SERVERD'))
  #set ($tag = $title.replaceFirst('SERVERD', 'SERVERX'))
  ##
  ## We can reuse and customize this snippet: https://snippets.xwiki.org/xwiki/bin/view/Extension/Display%20pages%20with%20a%20specific%20tag/
  ##
  #set ($references = $xwiki.tag.getDocumentsWithTag($tag))
  #foreach($reference in $references)
    #set ($document = $xwiki.getDocument($reference))
    #set ($label = $document.getTitle())
    [[$label>>$reference]]
  #end 
#end
{{/velocity}}

API文档和更多信息,请 https://www.xwiki.org/xwiki/xwiki/bin/bin/view/documentation/documentation/devguide/api/api/api/

您也应该了解,您还应该了解,自定义AWM应用程序后,使用AWM本身进行编辑时,应该要小心。例如,如果您添加了一个新字段Afaik,则可能会像上面的示例一样,将自定义完成为单位,因此您应该从文档历史记录中恢复它们并重新应用它们。

As far as I understand, you want to customize the "sheet" of the application which is used when displaying an application entry.

If you have a look a the documentation's section on customization, you get a lot of starting points on where you should be looking:

https://extensions.xwiki.org/xwiki/bin/view/Extension/App%20Within%20Minutes%20Application#HCustomization

This line would be interesting (but also the above links on how XWiki applications work):

The sheet, which is used to display and edit application entries (e.g. HolidaySheet)

In your case, it the document to customize (edit in wiki syntax mode) should be ServerCatalog.Code.ServerCatalogSheet

Inside that document, you have code automatically generated by AWM to which you can add a call to your macro.

## AWM generated code...
...

## Customization:
{{displayAssociatedPages /}}

Then, inside this macro (called displayAssociatedPages, in this example), you could do something like:

{{velocity}}
#set ($title = $doc.title)
## OR #set ($title = $doc.name), depending if your pages have titles

#if ($title.startsWith('SERVERD'))
  #set ($tag = $title.replaceFirst('SERVERD', 'SERVERX'))
  ##
  ## We can reuse and customize this snippet: https://snippets.xwiki.org/xwiki/bin/view/Extension/Display%20pages%20with%20a%20specific%20tag/
  ##
  #set ($references = $xwiki.tag.getDocumentsWithTag($tag))
  #foreach($reference in $references)
    #set ($document = $xwiki.getDocument($reference))
    #set ($label = $document.getTitle())
    [[$label>>$reference]]
  #end 
#end
{{/velocity}}

API documentation and more info at https://www.xwiki.org/xwiki/bin/view/Documentation/DevGuide/API/

Also, you should understand that once you customize an AWM application, you should be careful when editing it with AWM itself. For example, if you add a new field, AFAIK, you risk having the customizations done to your sheet, as in the above example, overwritten, so you should recover them from document history and re-apply them.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文