creating a dynamic table with nested macros
Asked by Kianusch:

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](/t5/image/serverpage/image-id/56924i5F6189A7D629EF1C/image-size/large?v=v2&px=999 "screenshot.JPG")


Answers:
author: Bill Bailey
body: 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.

comments: author: Kianusch
body: 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](/t5/user/viewprofilepage/user-id/1345631) 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?


author: Bill Bailey
body: 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](https://community.atlassian.com/t5/user/viewprofilepage/user-id/781467) 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](https://community.atlassian.com/t5/Confluence-articles/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.


author: Thomas Schlegel
body: Hi [@Kianusch](/t5/user/viewprofilepage/user-id/3305724)

and what is your question?

comments: author: Kianusch
body: 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](https://community.atlassian.com/t5/image/serverpage/image-id/56928i99F8E5995BB759CE/image-size/large?v=v2&px=999 "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\>"


author: Thomas Schlegel
body: I see - I get the same - But I need some time for investigation


author: Bill Bailey
body: 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.