Live Data Macro page: small mistake and doubt

Hi! I keep struggling to understand the power of Live Data Macro :slight_smile:

In its page under Extensions, Usage heading > Using Velocity, I read:

$services.liveData.render({
  'id': "recentPages",
  'properties': "doc.title,doc.location,doc.author,doc.date",
  'source': "liveTable",
  'sourceParameters': "translationPrefix=platform.index."
  'filters': "doc.location=help",
  'sort': "doc.date:desc",
  'limit': "5"
})

I think there are a couple of mistakes: one comma is missing at the end of the line for sourceParemeters, and limit expects an integer, not a string:

$services.liveData.render({
  'id': "recentPages",
  'properties': "doc.title,doc.location,doc.author,doc.date",
  'source': "liveTable",
  'sourceParameters': "translationPrefix=platform.index.",
  'filters': "doc.location=help",
  'sort': "doc.date:desc",
  'limit': 5
})

Now, if I put that code within XWiki Velocity Macro:

{{velocity}}
$services.liveData.render({
  'id': "recentPages",
  'properties': "doc.title,doc.location,doc.author,doc.date",
  'source': "liveTable",
  'sourceParameters': "translationPrefix=platform.index.",
  'filters': "doc.location=help",
  'sort': "doc.date:desc",
  'limit': 5
})
{{/velocity}}

I get some hieroglyph, but not a table.

image

What I’m missing, please? Should I be able to get the same table as if I use the code in the Usage > In Wiki Syntax heading?

Thanks!

Hello @Ricardo_Rodriguez,

Thanks for the report.
I’ve fixed the missing comma in the documentation.

Indeed, it shouldn’t be required to have to do anything more than calling the liveData script service in a velocity result to obtain a display of the Live Data in the UI.

I’ll take a look at it (Loading...).

In the meantime, a workaround is to add an additional html macro:

{{velocity}}
{{html}}
$services.liveData.render({
  'id': "recentPages",
  'properties': "doc.title,doc.location,doc.author,doc.date",
  'source': "liveTable",
  'sourceParameters': "translationPrefix=platform.index.",
  'filters': "doc.location=help",
  'sort': "doc.date:desc",
  'limit': 5
})
{{/html}}
{{/velocity}}

:slight_smile: It’s HTML!

More generally, couldn’t you use the livedata macro?

You, skillful guys, are able to read anything! :innocent:

Of course! And I’m enjoying it! But I’m also trying to understand XWiki’s capabilities and structure as much as possible. I am devoting as much time as possible to understanding how to use Live Data Macro macro to connect sources different from liveTable and outside the XWiki database.

For the record: I’m running XWiki Debian 16.0.0 on Ubuntu 22.04.3 LTS. Thanks!

After further discussion, using the script service when the liveData macro can be used is not a good practice.
Wrapping the call to the script service will work though, but it not the simplest or the most direct way to achieve this.
The $services.liveData.render method has mainly been introduced to use Live Data when xwiki macros are not available, for instance in velocity templates.

I see you’ve updated https://extensions.xwiki.org/xwiki/bin/view/Extension/Live%20Data%20Macro/#HUsingVelocity with a warning but for me it’s not enough. The warning is very cryptic and doesn’t explain what are the problems. We need to fix this.

If the issue is only the fact that it generates HTML then the doc should mention it, and the example should be modified to explain the context (that it’s an example when using the script inside a template and add the html macro to show an example when used in a wiki page). Are there problems other than the fact that it generates HTML?

Thx