No Coding Necessary: Building Confluence User Macros Cheat Sheet - Atlassian Summit 2010

  • Published on
    17-Oct-2014

  • View
    11.530

  • Download
    6

DESCRIPTION

 

Transcript

No coding necessary - cheat sheetMacro DefinitionMacro has a bodyAnything the user types within the body of the macro will be available in the macro in the $body variable.Use unprocessed macro bodyThe body of the macro will be output exactly as entered, including any HTML markup. For example if the macro body is 'body', it will be displayed as 'body' in the page.Escape HTML in macro bodyThe body of the macro will be output with HTML markup escaped. So if the macro body is 'body', it will be displayed as 'body' in the page.Convert macro body wiki markup to HTMLThe 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.Output - Macro generates HTML markupChoose this if you want to write your macro with HTML elements.Output - Macro generates wiki markupChoose this if you want to write your macro with wiki markup.Velocity Markup## Some textA comment#var1A variable#set($var1=abc)Setting a variable#if ($var1 == abc)#else#endSimple if-else statement$linkbodyEmbedding a variable within wiki markup#set($page = "${prefix}ref$pageid")Using formal references to refer to a variable within a stringjQuery tipsMust access as jQuery not $jQuery(document).ready(function(){jQuery calls here});Referencing Confluence Objects$bodyThe body of the macro$param0-nThe parameters passed to your macro (as available)$paramNamed parameters passed to your macro (as available)$configThe BootstrapManager object, useful for retrieving Confluence properties$contentThe current ContentEntity object that this macro is a included in (if available)$spaceThe Space object that this content object is located in (if relevant)$generalUtilA GeneralUtil object, with useful utility methods for URL encoding etc$actionA blank ConfluenceActionSupport object, useful for retrieving i18n text if needed$webworkA VelocityWebWorkUtil object, for its htmlEncode() method$reqThe current HttpServletRequest object (if the page is rendered as a result of an HTTP request)$resThe corresponding HttpServletResponse object (not recommended to be played with)$userAccessorFor retrieving users, groups and checking membership$permissionHelperFor determining user rightsExamples${content.id}Page id of current page[$762573668]Markup to create link to page with that id$action.getHelper().renderConfluenceMacro("{anothermacro}")Referencing another user macroRecent Confluence versions & dependenciesConfluencejQueryVelocity2.81.2.31.52.91.2.31.52.101.2.31.53.01.2.61.6.13.11.3.21.6.13.21.3.21.6.1ReferencesConfluence manual: Working with macroshttp://confluence.atlassian.com/x/eyACConfluence development: User macroshttp://confluence.atlassian.com/x/hREConfluence Shared user macro libraryhttp://confluence.atlassian.com/x/KoCjAgConfluence objects accessible from Velocityhttp://confluence.atlassian.com/x/EBQDAtlassian Confluence forumhttp://forums.atlassian.com/forum.jspa?forumID=96jQueryhttp://jquery.com/Firebughttp://getfirebug.com/Adaptavist jQuery versions articlehttps://www.adaptavist.com/display/jQuery/VersionsMacro 1: Response timeExample usage: {response-time}Please see this page for full listing: http://confluence.atlassian.com/display/DISC/Response+TimeMacro 2: color-table (final version)Example usage: {color-table:A2C1D5|BFEBEF}## Macro name: color-table## Macro has a body: N## Body format: n/a## Output: HTML#### Developed by: Charles Hall## Developed for: All users## Date created: 23/02/2010## Installed by: Charles Hall## Apply coloring to alternate rows of any tables with the class of confluenceTable.#set($oddcolor= $param0)#set($evencolor= $param1)## Check for valid odd color, otherwise use default#if (!$oddcolor) #set ($oddcolor="ffffff")#end## Check for valid even color, otherwise use default#if (!$evencolor) #set ($evencolor="ededed")#endjQuery(document).ready(function(){ //colour code odd and even table rows jQuery("table.confluenceTable tr:nth-child(odd)").css("background-color", "#$oddcolor"); jQuery("table.confluenceTable tr:nth-child(even)").css("background-color", "#$evencolor");});Macro 3: watermark (final version)Example usage: {watermark: logo.gif|no-repeat|1000}## Macro name: astrium-watermark## Macro has a body: N## Body format: n/a## Output: HTML#### Developed by: Charles Hall## Developed for: Astrium wiki## Date created: 31/03/2010## Installed by: Charles Hall## define a watermark image for the current page#set($image= $param0)#set($repeat = $param1)#set($minheight= $param2 + 'px')jQuery(document).ready(function() {/*Default theme*/if (jQuery("#header-menu-bar").length){ jQuery('#content').css('background-image', 'url($config.getBaseUrl()$content.getAttachmentNamed("$image").getDownloadPath())');## Add the specified repeat behaviour#if ($repeat) jQuery('#content').css('background-repeat', '$repeat');#end## Check for a specified minimum height#if ($minheight) jQuery('#content').css('height', '$minheight');#end jQuery('#content').css('vertical-align', 'top');}/*Left nav theme*/if (jQuery(".sidebar div.leftnav").length){ jQuery('#mainViewPane').css('background-image', 'url($config.getBaseUrl()$content.getAttachmentNamed("$image").getDownloadPath())');## Add the specified repeat behaviour#if ($repeat) jQuery('#mainViewPane').css('background-repeat', '$repeat');#end## Check for a specified minimum height#if ($minheight) jQuery('#mainViewPane').css('height', '$minheight');#end jQuery('#mainViewPane').css('vertical-align', 'top');}/*Clickr theme*/if (jQuery("#MegaFooter").length){ jQuery('#main').css('background-image', 'url($config.getBaseUrl()$content.getAttachmentNamed("$image").getDownloadPath())');## Add the specified repeat behaviour#if ($repeat) jQuery('#main').css('background-repeat', '$repeat');#end## Check for a specified minimum height#if ($minheight) jQuery('#main').css('height', '$minheight');#end jQuery('#main').css('vertical-align', 'top');}});Macro 4: draft-watermarkExample usage: {draft-watermark}## Macro name: draft-watermark## Macro has a body: N## Body format: n/a## Output: HTML#### Developed by: Charles Hall## Developed for: All users## Date created: 19/04/2010## Installed by: Charles Hall## inserts a Draft watermark image for the current page## N.B. Calls the watermark user macro## draft.gif must reside in "company" space#set($url="http://globalcorp.com/confluence/download/attachments/74416134/draft.gif")$action.getHelper().renderConfluenceMacro("{watermark:$url|no-repeat|1000}")

Recommended

View more >