This page last changed on Feb 18, 2007 by rosie@atlassian.com.
User macros are simple template-like macros that allow you to create simple formatting macros using the Confluence web interface.
If you want to distribute your user macro as a plugin, please see User Macro Plugins. If you want to create more complex, programmatic macros in Confluence, you may need to write a Macro Plugin. Note also that Macro Plugins and User Macro Plugins can appear in the Confluence Notation Guide, whereas User Macros do not.
To create a user macro,
You must be a Confluence administrator to create user macros.
- Go to the 'Administration Console' and click 'User Macros in the left panel. (Users of Confluence 1.1 or 1.2 will find user macros under Administration -> Macro Management -> User Macros)
- Click 'Create a User Macro' at the top of the list of macros.
- Enter the macro attributes as explained below this screenshot, then click the 'Save' button.

Options for 'Macro has a body':
When you select 'Macro has a body', anything the user types within the body of the macro will be available in the macro in the $body variable. The options below allow you to tell Confluence to pre-process the body before it is placed in the macro output.
- Use unprocessed macro body — the body of the macro will be output verbatim, including any HTML markup. For example if the macro body is <b>body</b>, it will be displayed as body in the page.
- Escape HTML in macro body — the body of the macro will be output with HTML markup escaped. So if the macro body is <b>body</b>, it will be displayed as <b>body</b> in the page.
- Convert macro body wiki markup to HTML — the body of the macro will be converted from wiki text to HTML markup. So if the macro body is *body*, it will be displayed as body in the page.
Writing user macros: some examples
- The name attribute of the macro is how you will use it from within a page, ie {name}.
- The template attribute of the macro is written in the Velocity templating language, and controls the rendering of the macro itself.
As an example, let's write a simple macro that simply creates a red box (using an existing Confluence style) around some text (useful for writing about error conditions for example - hence the macro name 'error').
After clicking "New User Macro", enter error as the Name of your macro, and then put the following in the Template text area:
<div class="errorbox">$body</div>
Then click Add. You should now see your new macro in the User Macros library, and you can now enable and disable it individually.
To use the macro within a page, you would add notation like:
{error}This is bad{error}
And your page would (magically!) have an error box on it, like so:
Another example to demonstrate how you can pass parameters into your macro. Say you wanted to write your own font colour macro:
<span style="color: $param0">$body</span>
The usage of this macro would be:
{colour:red}Some example text{colour}
which will produce:
Some example text
If your macro requires more than one parameter, you can use variables $param0 to $param9 to represent them. To specify multiple parameters, use:
Where red, blue and green are the 1st, 2nd and 3rd parameters respectively.
Available objects
The user macro above uses the $body object, which is available for use within your user macro template if the macro has a body.
You can pass parameters to your user macro in the same way as any other macro (separated by | signs), these parameters are provided to your template as param1, param2. . . paramN.
The complete list of objects available for use are:
Name |
Description |
Doc Reference |
$body |
The body of the macro (if the macro has a body) |
|
$param0-n |
The parameters passed to your macro (as available) |
|
$config |
The BootstrapManager object, useful for retrieving Confluence properties |
BootstrapManager |
$content |
The current ContentEntity object that this macro is a included in (if available) |
ContentEntityObject |
$space |
The Space object that this content object is located in (if relevant) |
Space |
$generalUtil |
A GeneralUtil object, with useful utility methods for URL encoding etc |
GeneralUtil |
$action |
A blank ConfluenceActionSupport object, useful for retrieving i18n text if needed |
ConfluenceActionSupport |
$webwork |
A VelocityWebWorkUtil object, for it's htmlEncode() method |
VelocityWebWorkUtil |
$req |
The current HttpServletRequest object (if the page is rendered as a result of an HTTP request) |
|
$res |
The corresponding HttpServletResponse object (not recommended to be played with) |
|
$userAccessor |
For retrieving users, groups and checking membership |
UserAccessor |
More information on object usage is available from the Velocity Template Overview.
I want to write a macro that uses other Confluence macros (like {color}) but when I type Confluences syntax inside the macro template it appears as is. Is there a way to gain access to this stuff from inside the Velocity template? Or do I have to write plain HTML? Any pointers are appreciated.

Posted by at Jul 08, 2004 09:23
|
Sure would be nice to have named parameters.
Unknown macro: {mymacro}
To prevent namespace collision, just stuff the macro params into a Hash with the same velocity object name as the macro itself, for example:
$mymacro.title $mymacro.name

Posted by timcolson at Aug 13, 2004 17:19
|
Doh... I put in an example but Confluence is trying to eval it inline – hence the unknown macro above.
{mymacro:title=Bright Idea Dude|name=Timo}

Posted by timcolson at Aug 13, 2004 17:21
|
I can't even make HTML work. It seems to be escaped, and therefore the tags appear in the page. Does anybody know what it takes to get either Confluence markup or html markup to appear when I use $body in the macro?

Posted by mankin at Aug 27, 2004 22:25
|
So it appears the $param1-n are passed in as strings. How can I pass in a value to determine how many times I loop? I want a macro that says Unknown macro: {tab} where $param1 indicates how many times to loop.
So my template looks like this:
#foreach( $foo in 1 .. $param1 )
$nbsp;
#end
However, this does NOT work. Any ideas how I might make this work? The velocity documentation says I should be able to specify a range like [$foo .. $bar], but the only way I've been able to make this work is where I #set($foo=1) and #set($bar=3). How can I let my $param1 define how many times I loop?

Posted by jamezzz at Dec 14, 2004 12:32
|
Is there any documentation on how to actually write the macro itself?
For instance, I've noticed that page book marks (set by the tag) are written in the page as
but confluence silently ads the page name, so that you end up with:
<a name="PageName-sectionName></a>
where's the doco that tells me what this $page variable is called and how do I use it?

Posted by snike at May 18, 2005 02:16
|
This is not currently supported, because $param1 contains a string, and thus can't be used as a loop counter.
If you would like to see this capability in user macros, please file an enhancement request at http://jira.atlassian.com

Posted by cmiller at May 18, 2005 02:30
|
what has VelocityWebWorkUtil been renamed to?

Posted by snike at May 18, 2005 21:01
|
Where to get more detailed information about these objects?

Posted by zoechi at Jun 23, 2005 07:40
|
Where to get more detailed information about these objects?

Posted by zoechi at Jun 23, 2005 07:40
|
It would be very HELPFUL if on the page above you added links
to what on earth a GeneralUtil or BootstrapManager provide,
e.g.
http://www.atlassian.com/software/confluence/docs/api/latest/com/atlassian/confluence/setup/BootstrapManager.html
http://www.atlassian.com/software/confluence/docs/api/latest/com/atlassian/confluence/util/GeneralUtil.html
http://www.atlassian.com/software/confluence/docs/api/latest/com/atlassian/confluence/core/ConfluenceActionSupport.html
And I'm guessing this is ContentEntity...
http://www.atlassian.com/software/confluence/docs/api/latest/com/atlassian/confluence/core/ContentEntityObject.html
Etc...
Wikis are supposed to be all interlinked after all...

Posted by marvingreenberg at Jul 08, 2005 10:05
|
yes, i have the same problem. Is there a velocity- available function that forces the rendering of some wiki-formatted text?

Posted by at Aug 26, 2005 05:29
|
This is not possible as all text entered in the body of a user macro is left alone by the renderer.
Cheers,
Dave

Posted by dave@atlassian.com at Aug 28, 2005 23:50
|
Well, it's actually easily doable in Confluence:
The above code runs correctly in 1.4.3 (didn't test it in earlier versions but no reason why it should not work).
I truly wish that Confluence could provide better docs for the objects listed though, 'cause obviously it's too skimpy to be of much help to people.

Posted by mingyi at Aug 29, 2005 12:37
|
Yeah, same wish here. I'll check if I could add it to wish list (or it's already there).
Would it be difficult to implement it? Seems to me that Confluence just needs to pass in an object with a method that runs wiki syntax engine.

Posted by mingyi at Aug 29, 2005 12:44
|
Confluence has an Unknown macro: {html} macro that allows you to enter HTML directly into the wiki page.
By default, this macro is disabled for security reasons. To enable this macro, go to "Administration | General Configuration | Plugins | HTML Macros" and click enable plugin.

Posted by daniel@atlassian.com at Aug 29, 2005 18:17
|
A feature request has been raised for this and can be tracked via http://jira.atlassian.com/browse/CONF-3887
If you would like to see this feature included in confluence, please vote for it.

Posted by daniel@atlassian.com at Aug 30, 2005 18:20
|
It's a bit tricky but the following works:
#set($globalHelper=$action.getGlobalHelper())
#set($renderer=$globalHelper.getWikiStyleRenderer())
#set($context=$content.toPageContext())
#set($renderedContent=$renderer.convertWikiToXHtml($context, $body))
${renderedContent}

Posted by thragor@gmx.net at Sep 29, 2005 09:15
|
Well, this is even more powerful than any $renderedBody-variable which might be used. Just see here:
...
#set($context=$content.toPageContext())
#set($renderedContent=$renderer.convertWikiToXHtml($context, "{panel:title=My Title}${body}{panel}))
${renderedContent}
The only problem I have now is that I also want to create Panels containing Wikified-Lists this way. E. g.:
#set($content="{panel}")
#foreach($line in $array)
#set($content="${content}* ${line}<newline>")
#end
The <newline> is my problem: How to get a newline-character inside there so that Confluence finally renders a content like this:
{panel}
* line 1
* line 2
{panel}
?? '\n' does not work. It will render a content like:
{panel}* line 1\n* line 2\n{panel}
Any ideas welcome!

Posted by thragor@gmx.net at Sep 30, 2005 06:57
|
Oops. One step to far. You can even make it much more easy and without errors when rendering such errors in the global-templates-preview:
#set($globalHelper=$action.getGlobalHelper())
#set($renderedContent=$globalHelper.renderConfluenceMacro($body))
${renderedContent}

Posted by thragor@gmx.net at Sep 30, 2005 09:59
|
Hm. Seems as if this only works for simple bodies. I. e. you either have to use the first workaround and ignore the errors in the Global Templates Preview or you get even more complex. The following is an example-macro which just renders the body (but of course you might extend $wiki as you like):
#set($wiki=$body)
#set($globalHelper=$action.getGlobalHelper())
#if($content) ## i. e. we render a normal page
#set($renderer=$globalHelper.getWikiStyleRenderer())
#set($context=$content.toPageContext())
#set($xhtml=$renderer.convertWikiToXHtml($context, $wiki))
#else ## we are e. g. in Global Template Preview
#set($xhtml=$globalHelper.renderConfluenceMacro($wiki))
#end
${xhtml}

Posted by thragor@gmx.net at Sep 30, 2005 10:41
|
For the different behavior of renderConfluenceMacro and convertWikiToXHtml I raised an issue CONF-4220 which hopefully will be fixed soon.
The different behavior will show up as soon as e. g. $body contains macros which need access to the current space. E. g. {blog-posts} will fail with just using renderConfluenceMacro (it won't show the news of the current space).

Posted by thragor@gmx.net at Oct 05, 2005 03:10
|
I think it would be a good idea to have a "User Macro Library" just as it has been introduced for the "Scaffolding Macros". They might serve as examples and of course might be of general interest. I think this is better than the alternative to make every User Macro a Confluence Extensions appearing in the Extension Space. Perhaps we could in addition point from the Extension Space to the User Macro-Library instead.

Posted by thragor@gmx.net at Oct 13, 2005 03:59
|
Is there any chance to make the User Macros visible in the Notation Guide? Otherwise they will have to be documented in some of the spaces to make them known to the Confluence-Users.
I suggest something like JavaDoc, e. g.
#/**
#* Does *something* useful.
#* @notation \{something-useful\}_Content_\{something-useful\}
#* @notation \{something-useful:_Some Title_\}_Content_\{something-useful\}
#* @param 0 some useful title
#* @param 1 some useful option
#* @param body some useful content
#*/
Where the description will appear as rendered Wiki-Content in the Comment-column while the notations are listed (separated by newlines) in the Notation-column.

Posted by thragor@gmx.net at Oct 13, 2005 04:12
|
This feature request is being tracked at CONF-2294. Please go vote for it.

Posted by jnolen at Oct 13, 2005 13:33
|
Thanks for the help commenters - here is the hardest little thing I have had to write:
#set($globalHelper=$action.getGlobalHelper())
#set( $news=$space.blogPosts )
#set( $count=0)
#foreach($post in $news)
#set($count=$count+1)
#end
#set($number= $generalUtil.convertToInteger($param0))
#set($start=1)
#if( $number > 0)
#set($start= $count - $number)
#end
#foreach( $index in [$count .. $start] )
#set($index2= $index - 1 )
#foreach($post in $news.subList( $index2, $index) )
<a href="/confluence/display/pages/viewpage.action?pageId=${post.id}">$post.realTitle</a><br/>
#end
#end
This provides links the the indicated number of recent log posts. The hard part here was reversing the list. Could not get size, Collections.reverse or even get to function ...

Posted by jive at Nov 07, 2005 20:27
|
Good hint Mark
one little bug: you forgot the second " in the line before last:
\#set($globalHelper=$action.getGlobalHelper())
\#set($renderer=$globalHelper.getWikiStyleRenderer())
\#set($context=$content.toPageContext())
\#set($renderedContent=$renderer.convertWikiToXHtml($context, "{panel:title=My Title}${body}{panel}"))
${renderedContent}

Posted by baaderst at Dec 13, 2005 11:19
|
It looks like parameters are now 0-based rather than 1-based. Incrementing i in $parami in all my user macros fixed the problem I had after upgrading from 1.3.5 to 2.1.1.

Posted by oalaoui at Jan 12, 2006 16:46
|
Btw the following should be fixed in the page (replace bold by param0):
You can pass parameters to your user macro in the same way as any other macro (separated by | signs), these parameters are provided to your template as param1, param2. . . paramN.

Posted by oalaoui at Jan 12, 2006 16:49
|
hmm this is odd: with only one parameter, it only works if I use 0 as the start index, but with multiple parameters i can keep using 1 as the start index:
<a xhref="notes:>$param0</a>
Could this be a bug?

Posted by oalaoui at Jan 12, 2006 17:07
|
Even with multiple parameters the first parameter is still $param0 on testing in Confluence 2.1.2.
That is, the following macro:
first: not shown, second: $param1, third: $param2
When called like this:
gives:
first: not shown, second: bar, third: baz
Cheers,
Dave

Posted by dave@atlassian.com at Jan 13, 2006 00:09
|
You're right David. User error. Thanks for checking.

Posted by oalaoui at Jan 14, 2006 13:12
|
Hello,
I need to have a way to decide whether a page is exported as PDF or not. I thought I might use $action.isPrintableVersion() but this seems to return false for PDF generation. Does anyone know any other way to do this?
Regards,
Mark

Posted by thragor@gmx.net at Jan 26, 2006 02:25
|
There isn't any way to do this at present, but in 2.1.4 you will be able to do:
#if ($renderContext.outputType == "pdf")
I'm a PDF
#else
c'est ne pas un PDF
#end
Tom

Posted by tom@atlassian.com at Feb 02, 2006 22:24
|
I'm using the technique I learned on this page to fetch a numeric value from a database, like this:
#set( $query = "{sql:jndi=Reports |heading=false| table=false}select $param0 from metrics where year=$param1 and ticker='${content.realTitle}'{sql}")
#set($globalHelper=$action.getGlobalHelper())
#set($renderedContent=$globalHelper.renderConfluenceMacro($query))
${renderedContent}
The value is returned, but it comes back with leading and trailing newlines. This is a problem, because sometimes I want to follow the value with a "%", as follows. I can't put the "%" inside the macro, because not all invocations of the macro want the "%".
{metric:expense_ratio|2005}%
produces:
0.015 %
I've tried trim and replace functions, to no avail (but perhaps I didn't invoke them correctly; I am not a java programmer). Trim seems to ignore the newlines, and when I did $globalHelper.renderConfluenceMacro($query).replace("\n",""), the macro returned "${renderedContent}" (that is, the literal variable name, not the rendered content!)
Can someone show me how to trim these newlines?

Posted by cherylchase at Feb 08, 2006 09:22
|
I would expect
$globalHelper.renderConfluenceMacro($query).trim()
to work.
Or
$globalHelper.renderConfluenceMacro($query).replaceAll("\n","")
replace() expects characters rather than strings, so the code you used above coulsn't find a function to call.

Posted by tom@atlassian.com at Feb 08, 2006 17:00
|
For some reason, replaceAll("\n","") seem to work.
Here's my code and the output (I've put "x" on either side of \${renderedContent} in the macro, to make more obvious the source of the unwanted space):
#set( $query = "{sql:jndi=Reports |heading=false| table=false}select $param0 from metrics where year=$param1 and ticker='${content.realTitle}'{sql}")
#set($globalHelper=$action.getGlobalHelper())
#set($renderedContent=$globalHelper.renderConfluenceMacro($query).replaceAll("\r",""))
x${renderedContent}x
| Expense Ratio | {metric:expense_ratio|2005}% |

Posted by cherylchase at Feb 09, 2006 00:18
|
I think that the position of the "x" characters in the above make clear that the unwanted newline is not in the result of $renderedContent=$globalHelper.renderConfluenceMacro($query), so no manipulation of $renderedContent is going to help. For some reason, the user macro execution process is adding newlines to what I want to return.
Is there some sort of a context that I can manipulate, to tell it that my output is inline?

Posted by cherylchase at Feb 09, 2006 12:23
|
Not easily. There's some CSS hacks you can use, eg:
Then use following CSS:
Or something along those lines. However, it seems that MSIE doesn't cope well with this (or anything else really, I do wish they'd hurry and get IE 7 out as then web development will be significantly easier as everything runs to one standard).
The only reliable way we've found is to create a java plugin version of the macro. Fairly easy to do, but a complete pain when all you want is a quick user macro.
Ideally, we need an "Display inline" checkbox when creating a user macro - there are vast numbers of cases when people want to display just some inline text or whatever, but can't because it gets wrapped in <p> tags by default. For example, you might want a common thing like company name, email address, product name, etc., to be ouput by a user macro = ensures consistency across a big site and also allows you to easily update in one place at a later date. However, the lack of inline ability for user macros (even if you try digging in to the API from them there is still no joy) thwarts every attempt. 

Posted by gfraser at Feb 09, 2006 12:46
|
I've raised an issue: http://jira.atlassian.com/browse/CONF-5456

Posted by tom@atlassian.com at Feb 09, 2006 18:08
|
Am I useless, or is the API documentation?
I was trying to find a function like 'getparent' or 'getchildren' and could find absoluteley no mention of it in the API docs for the objects listed above. However, on a last-ditch whim, I tried:
#set($result=$content.getParent())
$ Unknown macro: {result}
#set($result=$content.getChildren())
$
and to my amazement and horror, they both worked.
So is there any REAL API documentation around, or am I completely missing something in the documentation linked above?

Posted by jamesmortimer at Apr 12, 2006 17:20
|
Should have used {code} tags
#set($result=$content.getParent())
${result}
#set($result=$content.getChildren())
${result}

Posted by jamesmortimer at Apr 12, 2006 17:21
|
Whilst there are definitely still holes in documentation surrounding Confluence, in this case there is a description of the variables available and links to their API documentation listed in the available objects section above. It lists the variable and gives a link to the API docs for that object (in this case, $content and ContentEntityObject).

Posted by david@randombits.org at Apr 12, 2006 18:19
|
Ah...sorry just reread your original post and now get what you're on about. ContentEntityObject is the abstract base class for a few different types of content, including BlogPost, Comment, SpaceDescription and of course Page. The only one of those which allows a parent/child hierarchy is Page, which is why there is no 'getParent()' method in ContentEntityObject. So, the macro you have above will only work on pages - if you use it in a blog post or a comment it will throw an exception. To make sure it doesn't break on other types of content, you could add a test, something like the following:

Posted by david@randombits.org at Apr 12, 2006 18:31
|
Thank you, David. That is precisely the page that I am looking at, and I find absolutely no mention therein of a getParent() or getChildren() methods. What am I missing?

Posted by jamesmortimer at Apr 13, 2006 08:34
|
I replied to quickly without seeing your second comment. I wish I could delete comments from here.
I can see now the connection.
My problem was that I was looking at the 'PageContentEntityObject' subclass of the 'ConentEntityObject' and for some reason 'AbstractPage' is actually subclass of 'SpaceContentEntityObject' and 'Page' is a subclass of 'AbstractPage'. I was only looking down the 'pagecontententityobject' branch.
Is there a better way to navigate the API to find out the relationship between Page, AbstractPage, ConfluenceEntityObject, etc....?
Anyway, answer to my original question is, as I expected, that it was me that was useless. THanks for your help.

Posted by jamesmortimer at Apr 13, 2006 08:43
|
Yeah, the PageContentEntityObject threw me for a minute too when I was looking at the API again - I think the idea is that subclasses of PageContentEntityObject are content which belongs to a Page, while SpaceContentEntityObject subclasses are for content that belongs to a Space...
As for a better way to navigate the API, there are none that I'm aware of. Learning how to walk the paths of Confluence have been a combinaton of trial-and-error and asking lots of questions. It's a complex application, built on several layers of foundation, which makes it hard to dig into sometimes. On the up-side, JIRA is worse 

Posted by david@randombits.org at Apr 13, 2006 10:18
|
Anyway to create link using a custom page template using a user macro?
An attempt at hacking it in for instance. Sort of works but doesn't pick up the template name.
<a href="/confluence/pages/createpage-entervariables.action?spaceKey=$space&parentPageId=${param0}&fromPageId=${param0}&title=${param1}&linkCreation=false&templateName=Status%20Report">New Status Report</a>
Usage:
{new_status_report:1234|Status Report 2006-04-05}

Posted by troymckinnon at Apr 24, 2006 16:28
|
The create page macro might do what you are after as you can pre-define prefix and postfix for the page title, and if no page title is specified, the user is asked to enter one.
http://confluence.atlassian.com/display/CONFEXT/Create+Page+Macro

Posted by gfraser at Apr 24, 2006 16:39
|
to 'hack' the url and supply a template properly, you require a template ID. See the create-page macro mentioned below. Also, the linking plugin works well in most cases.

Posted by jamesmortimer at Apr 25, 2006 09:28
|
How to enumerate all registered user and get their full names?
#set($users=$content.getUserAccessor().getUsers() )
#foreach($user in users)
$user.name
#end
The code above doesn't work 

Posted by art@deep.ru at May 09, 2006 02:05
|
The property you want is "fullName" so the following may work better:

Posted by dhardiker@adaptavist.com at May 09, 2006 04:04
|
Unfortunately the enumeration doesn't work at all.
Seems like The getUsers() returns an empty array.

Posted by art@deep.ru at May 09, 2006 05:10
|
Are you using LDAP or another external user authentication system? I think if you are using LDAP for your user authentication, .getUsers() returns an empty array.

Posted by jamesmortimer at May 11, 2006 08:51
|
Did anyone every contribute how to render a newline in a velocity script?
I'm using the following patchy workaround (there must be an easier way?):
#macro(newline)
#end
#set($newline="#newline()")
which with Mark's code above would look like:
#set($content="{panel}")
#foreach($line in $array)
#set($content="${content}* ${line}$newline")
#end
which renders properly as:
{panel}* line 1
*line 2
{panel}
The idea of assigning it to a variable is that using "#newline()" in loops eventually slows down the velocity engine considerably compared to a simple varialbe replacement.
you may also like to use the following to replace all \n occurances with a newline character:
#set($mycontent=$mycontent.replaceAll('\\n',$newline))

Posted by jamesmortimer at Jun 03, 2006 14:53
|
Did anyone report a workaround for newline in velocity script 'User Macro's?
I'm using the following patchy workaround, but there must be a better way.
#macro(newline)
#end
#set($newline="#newline()")
Now, $newline or #newline() will return a newline character. $newline is faster as the velocity renderer doesn't have to start up and re-render the 'newline' content each time. It actually makes a difference if you are using it in a large loop.
So mark's code would look like:
#set($content="{panel}$newline")
#foreach($line in $array)
#set($content="${content}* ${line}$newline")
#end
#set($content="$content$newline{panel}")
which renders
and you might want to use it like this, to replace all \n with newline characters:
#set($wiki=$wiki.replaceALL('\\n',$newline))

Posted by jamesmortimer at Jun 03, 2006 15:06
|
Please disregard (or delete if you are able) one of the two duplicated comments above. Thanks.

Posted by jamesmortimer at Jun 03, 2006 15:10
|
Depending on your opinion, this code for getting a newline character is a bit cleaner but still patchy.
#set($newline="")#set($newline=$newline.format('%n',null))
- you need to have a string defined to get at the .format property, #hence set($newline="")
- %n is a platform independant newline characters
- null is because format requires an object for any replacement codes. We're not using any.

Posted by jamesmortimer at Jun 03, 2006 16:29
|
I am astonished. With Confluence 2.2 named parameters seem to work. Just tried by try-and-error and got e. g. $paramstyle to refer to the value of argument "style=something".
It would be nice to know if this is a "first try" or if this is finalized so that we can base new user macros on this new feature. And if so, it should be documented here 

Posted by thragor@gmx.net at Jun 09, 2006 05:19
|
Any have a tip how to access the tiny link – e.g., "http://confluence.atlassian.com/x/hRE" – for the current page within a user macro? Thanks!

Posted by lima at Jul 10, 2006 11:54
|
Is there any way to change the text color/size of just the title line in the panel macro?
thnx,
steve

Posted by steves at Jul 27, 2006 14:10
|
You will need to modify the panelHeader class in the CSS file (confluence/WEB-INF/classes/styles/site-css.vm).
Cheers,
Dave

Posted by dave@atlassian.com at Jul 27, 2006 19:59
|
The issue says that it is resolved, but unfortunately only for macros which have a body. I am writing a small macro to create a link to a particular space, and I want it to render after I create the link (so that it will insert the "create page" in the case that the link target doesn't already exist (it is for an acronym space). So my macro doesn't have a body (i.e. {acronym:TLA}) I really don't want it to have to have a body (unecessary typing for my users). So I would still like to see and "Inline" checkbox.
In the meantime, I used this, which is awkward, but works on both IE and firefox:
#set($renderedContent=$renderer.convertWikiToXHtml($context,"[$param0|ACRO:$param0]"))
#set($renderedContent=$renderedContent.replaceAll("<p>",""))
#set($renderedContent=$renderedContent.replaceAll("</p>",""))
${renderedContent}

Posted by shart at Sep 14, 2006 11:29
|
I use this. Equally awkward, but with the added features of:
- works in templates, preview or page views
- has a friendly 'hover text' indicating that you will navigate to a new space
- replaces only leading/training <p> tags, not all <p> tags, which isn't important in this use case but helps with other render tasks
#set($wiki="[$param0|HELP:$param0]")
#set($globalHelper=$action.getGlobalHelper())
#if($content) ## i. e. we render a normal page
#set($renderer=$globalHelper.getWikiStyleRenderer())
#set($context=$content.toPageContext())
#set($xhtml=$renderer.convertWikiToXHtml($context, $wiki))
#else ## we are e. g. in Global Template Preview
#set($xhtml=$globalHelper.renderConfluenceMacro($wiki))
#end
## remove leading <p> and trailing </p>
#if($xhtml.startsWith("<p>",0) && $xhtml.endsWith("</p>"))
#set($len=$xhtml.length()-$generalUtil.convertToInteger(4))
#set($xhtml=$xhtml.substring(3,$len))
#end
#set($xhtml=$xhtml.replaceAll("title=\"$param0\"","title=\"Look up \'$param0\' in the Help space.\""))
${xhtml}

Posted by jamesmortimer at Sep 14, 2006 14:35
|
any indication yet if this is a hidden alpha-feature or something that will persist?

Posted by jamesmortimer at Sep 14, 2006 14:37
|
Some questions about usermacros:
1. What's the function to add a label to a page? I want to add an unique automatically generated label to a page to use in template, by writing an usermacro. With add-label macro you can't do this.
I have
but doesn't work. A counter would be better than the pageId, but is it possible to store a variable on a page? So for each new added page the counter does +1: test1, test2, test3, test4, ..?
Thanks a lot.
2. The function to get the templateID if you know the templatename?

Posted by dieter at Sep 28, 2006 09:40
|
1. There's no way to add a new label from within a user macro, because you can't create new objects in Velocity. You'll need to write a macro plugin to do this.
2. The PageTemplateManager is responsible for this. The method is getPageTemplate(String name, Space space), where you pass a null space for a global template. However, you can't access this object from user macros either, so you'll need to write a macro plugin if you want to do this.
The Velocity context for user macros only includes objects used for common operations. Including all the Confluence managers would make page rendering slower and consume more memory. Macro plugins allow full access to everything inside Confluence, and are not difficult to get working with a small bit of Java knowledge.

Posted by mryall at Oct 30, 2006 18:24
|
How can i just find the username of the currently logged in user? this is the code I have write now:
#set($user = $userAccessor.getUser())
$user

Posted by jguthrie at Nov 13, 2006 18:45
|
$user.name

Posted by tom@atlassian.com at Nov 13, 2006 23:49
|
If I have this code in a macro called currentuser:
#set($user = $userAccessor.getUser())
$user.name
and on my page, I put this code: Unknown macro: {currentuser} , what prints on the page is
$user.name
So it is not working quite yet... I would also like to have this working on each page without manually putting the macro on each page...

Posted by jguthrie at Nov 14, 2006 11:23
|
Hi Jeff,
here is a small usermacro that gives you information about the current user.
Get the $user object first and then obtain:
fullName - full name of an user
email - user's email (if exists)
name - user's login name
#set($user=$action.remoteUser)
$user.fullName
$user.email
$user.name

Posted by ivan@atlassian.com at Nov 15, 2006 20:13
|
Oh thats how you do it, thanks! Where can i find other properties I can grab about the current user or other info? (using $action.??? or $user.browsertype? etc...)
Thanks!

Posted by jguthrie at Nov 16, 2006 10:56
|
I'm a little confused on how to use the New Code Macro with Javascript.
On many of your Macro pages, there is a Version area within a table that has the ability to expand or hide info for each version. (hide-desc, show-desc)...There's no macro in the confluence library that does this and the page tree plug in is for different pages. I can't seem to get the New code one to work though. Could someone show me an example of how something like this is done or used.

Posted by tamish@vsp.com at Nov 16, 2006 15:29
|
This is great to know.
Quick question however, is the use of $action.remoteUser security safe?. i.e to find the current user, does this use a call to return the sessions authenticated user, or does it simply extract the name from a cookie or something silly?
From what I can tell it's using a call through authenticated user or something involving the session info, so it should be safe against someone seeding a username in a form with a REMOTE_USER value. ??
I only ask because I want to be sure I can use it in a certain way.

Posted by andrew.whyte@sparq.com.au at Jan 28, 2007 18:02
|
$action.remoteUser returns you the Atlassian User "User" object that has been properly authenticated through the session. It's not a String value and cannot be spoofed by simply passing through a variable in the headers or in the URL.
The only realistic way I can think of to change user, is to log packet data coming from the confluence server and then hijack the session for the appropriate user. Using SSL would remove that option though.
Knowing most users - it would probably be easier just to shoulder surf, or even just bribe them with chocolate.

Posted by dhardiker@adaptavist.com at Jan 28, 2007 18:13
|
|