How to include token or variable for Invoice number under the message templates for Memberships - Receipt (on-line)
The tokens you can use in a message template are a bit random, just what the developer added to the template. In this case, the contribution id can be found with {$contributionID}. However, that is not the same as the invoice_number. I could not find a token for the invoice number. But the templates are generated by smarty, and in smarty you can use the CiviCRM api. So the following line gets the invoice number:

{crmAPI var='invoiceReference' 
        entity='Contribution' 
        action='getvalue' 
        return="invoice_id" 
        id=$contributionID}


You can print it with {$invoiceReference}