Countdown Timer for Confluence
Breadcrumbs

How to pass in the date from other macros

Background


Sometimes, there is a requirement to generate the countdown based on the output from other macros 


This is a workaround by using Confluence user macro to redirect the output of the encapsulated macros as the date paramater for the Countdown macro

The date format generated by the other macros must follow the format of dd-mm-yy.

Otherwise, additional preprocessing steps can be added in the user macro code

Instructions


Setting up the user macro

  1. Log in as Confluence Admin

  2. Go to Confluence Administration > General Configuration 

  3. Click on User Macros on the left side menu

  4. Click on Create a User Macro

  5. Fill in the details as the table below

    Macro Name

    countdownbody

    Visibility

    Visible to all users in the Macro Browser

    Macro Title

    Countdown Date in Body

    Description

    Uses the output of other macros as the date input to the Countdown Timer plugin

    Categories

    Visuals & Images

    Icon URL

    Documentation URL

    Macro Body Processing

    Rendered

    Template


    ## Macro title: Countdown Date in Body
    ## Macro has a body: Y
    ## Body processing: Rendered
    ##
    ## @noparams
    #set ($index = $body.indexOf('</span>'))
    #set ($index = $index - 8)
    #if ($index > 0)
       #set ($startIndex = $index - 8)
       #set ($date = $body.substring($startIndex, $index))
    #else
      #set ($date = $body)
    #end
     
    <ac:structured-macro ac ac:name="countdown" ac:schema-version="1">
       <ac:parameter ac:name="countdowndate">$date</ac:parameter>
       <ac:parameter ac:name="centered">true</ac:parameter>
       <ac:parameter ac:name="style">Black</ac:parameter>
    </ac:structured-macro>
    


     

  6. Click on Save button


Using the user macro

  1. Go to the page or template

  2. Add the Countdown Date in Body user macro instead of Countdown macro
    countdown date in body.png

  3. Add the other macros which will provide the date 

    Plain Date

    Other Macro

    countdown plain date.png

    countdown confiforms.png