Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

creating a dynamic table with nested macros

Kianusch June 7, 2019

hi,

i want to build a dynamic table (with costumizable amound of tablerows). For that I want to nest macros.

 

 

the outter macro rn:

<table>

<tr>

<th>header1</th>

<th>header2</th>

</tr>

$body

</table>

 

 

the inner macro rn:

<tr>

<td>cell1</td>

<td>cell2</td>

</tr>

 

 

screenshot.JPG

2 answers

1 accepted

0 votes
Answer accepted
Bill Bailey
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 7, 2019

So why not write it as single user macro with parameters to construct the size table you want with the appropriate variables?

You could for example, have the cell values as a comma-separated list in the macro body, that the macro can then parse.

A single macro is probably going to be easier to get working.

Kianusch June 11, 2019

I already thougt about that, but it does not fit my case. At the end I want a dynamic table with enum parameters like

## @Param Example1:title=Example1|type=enum|enumValues= cell1,cell2,cell3,cell4

in the cells.

I dont think that this is possible with only one macro isn´t it?

Bill Bailey
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 11, 2019

Well I know of no limit on the number of parameters. But what I was suggesting is a comma-deliminated set of values that you place in the body of the macro. Then you can parse that string to get your values. You can even make it easy by have comma separate values, and semicolons separate rows/sets of values. Then you can have a data set as large as you want.

With Velocity you have access to a number of Java string methods, for example .split that you can use to parse a long string in the a list.

 

OR if you are lazy like me, you use a CSV file and import the values from an attachement. Fortunately,  Davin Studer  has written an excellent pair of articles on a user macro that builds a table from a CSV file. Here is part one:

A-User-Macro-to-Create-a-Table-From-an-Attached-CSV-File-Part/ba-p/738757

 

You could modify it so that rather than reading a CSV list from a file, it could be read from $body to make it easier.

0 votes
Thomas Schlegel
Community Champion
June 7, 2019

Hi @Kianusch  

and what is your question?

Kianusch June 7, 2019

Hi Thomas,

thank you for your quick answer.

My problem is, that the output of nesting the macros is not an table.

The output looks like this

2.screenshot.JPG

 

I think the code of the inner macro is rendert wrong sothat the output of the inner macro is:" cell1 cell2 " instead of "<tr><td>cell1</td><td>cell2</td></tr>"

Thomas Schlegel
Community Champion
June 7, 2019

I see - I get the same - But I need some time for investigation

Bill Bailey
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 7, 2019

You may need to play with the Macro Body Processing settings. I think you may need to set one or both to unrendered.

When you are experimenting, it might be useful to use the browser inspect function to what is actually being output.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events