How do I create a preformatted and editable table user macro in Confluence?

E July 24, 2012

We want to create a user macro that generates a formatted table in a page (Confluence 4), but again we're struggling with the syntax.

The code below inserts a table, but you cannot edit it

## @noparams
<table>
<tr>
<th>Parameter</th>
<th>Description</th>
</tr>
<tr>
<td></td>
<td></td>
</tr>
</table>

We've selected no macro body.

The documentation doesn't explain how to do this.

6 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
CharlesH
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.
July 26, 2012
The ## is a comment in velocity language. JQuery is a JavaScript library bundled in Confluence. You'd use this In a script tag, written as part of the macro output. You've got the right idea on wrapping the table in a div, but in the approach i outlined this would be in the Confluence page, not the macro. The jquery to insert the column headings would be something like this (untried): jQuery('#$paramtablediv table tr:first').before('ParameterDescription'); If wrapping the table with div is not practical then you could have the jquery selector pick out all tables on the page, or just the first/ last...
0 votes
CharlesH
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.
July 26, 2012
Okay, I'd suggest the following approach - create the table content in a regular table as normal. Wrap this table in a div tag, with an Id value. Now all you'll need is the user macro to stick the table column headings and any other formatting into the table indicated by the supplied Id value ( which belongs to the parent div). This can be achieved quite easily with the aid of a few lines of jquery. You could supply 2 params to the macro, one being the I'd of the parent div, the other being a CSS class to apply styling nicely.
E July 26, 2012
The few simple lines of jquery would be what, and do what? Is that the ## @ bits? Should it be escaped or rendered?
E July 26, 2012
I get to here and then I'm stuck
## @param Head1:type=string|desc=Heading
## @param Head2:type=string|desc=Heading
## @param Cell1:type=string|desc=cell
## @param Cell2:type=string|desc=cell

<div id="preformattedtable">
<table>
<tr>
<th>$paramHead1</th>
<th>$paramHead2</th>
</tr>
<tr>
<td>$paramCell1</td>
<td>$paramCell2</td>
</tr>
</table>
</div>


E July 26, 2012

Is correct?

## @param Head1:type=string|desc=Heading
## @param Head2:type=string|desc=Heading
## @param Cell1:type=string|desc=cell
## @param Cell2:type=string|desc=cell

#set ($paramHead1 ="Parameter")
#set ($paramHead2 ="Description")

<div id="preformattedtable">
<table>
<tr>
<th>$paramHead1</th>
<th>$paramHead2</th>
</tr>
<tr>
<td>$paramCell1</td>
<td>$paramCell2</td>
</tr>
</table>
</div>

0 votes
E July 26, 2012
Unfortunately not. The pages have been imported.
0 votes
CharlesH
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.
July 26, 2012
Would a template be more appropriate here? It would certainly solve the problem of being editable.
0 votes
E July 25, 2012

## @noparams

<ac:macro ac:name="unmigrated-wiki-markup">

<ac:plain-text-body><![CDATA[|| Test Name|| Pass/Fail||

|$body | $body|

]]></ac:plain-text-body></ac:macro>

0 votes
E July 25, 2012

I've also tried

## @noparams

<ac:macro ac:name="unmigrated-wiki-markup"><ac:plain-text-body><![CDATA[|| Test Name|| Pass/Fail||
|$body | $body|
]]></ac:plain-text-body></ac:macro>

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events